Android Layout- 具有相同父级的 RelativeLayout 和 LinearLayout 之间的约束
Android Layout- Constraint between the RelativeLayout and LinearLayout that has the same parent
我的 Android 应用程序中有一个布局文件,如下所示;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/myPage"
android:theme="@style/login"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:id="@+id/myimageview"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:src="@drawable/mypicture"/>
<com.myapp.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/myimageview"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="@string/mystring"
android:textColor="#fff"
android:textSize="12sp"
app:rt_fontWeight="light" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/password_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
app:theme="@style/loginTheme">
<android.support.v7.widget.AppCompatEditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:hint="@string/password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</RelativeLayout>
我想把 space 放在包含 RobotoTextView
的 RelativeLayout 和下面的 LinearLayout 之间layout.They 在我的布局中处于同一级别 file.Also 我的应用程序必须 运行 在不同的屏幕分辨率下。
一定是这个文本视图下的RobotoTextView和LinearLayout之间的约束之类的东西。
我在 LinearLayout 中尝试了 android:layout_marginTop
但它没有用。 RobotoTextView与LinearLayout
下的文本视图重叠
将此属性添加到底部布局,为其指定一个 id:
android:id="@+id/bottom"
还有这些到顶部布局:
android:layout_marginBottom="10dp"
android:layout_alignParentTop="true"
android:layout_above="@+id/bottom"
您可以将 10dp
更改为您喜欢的任何内容。
同时删除
android:layout_weight="1"
因为它仅适用于 LinearLayout
内的视图
你没有解释好,但是,我按照你的指示尽力了。
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/myPage"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/linearfirst">
<ImageView
android:id="@+id/myimageview"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
<com.myapp.RobotoTextView
android:layout_width="159dp"
android:layout_height="51dp"
android:layout_below="@+id/myimageview"
android:layout_alignStart="@+id/myimageview"
android:layout_alignLeft="@+id/myimageview"
android:layout_alignEnd="@+id/myimageview"
android:layout_alignRight="@+id/myimageview"
android:layout_marginStart="-15dp"
android:layout_marginLeft="-15dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="-23dp"
android:layout_marginRight="-23dp"
android:gravity="center"
android:text="@string/mystring"
android:textColor="#fff"
android:textSize="12sp"
app:rt_fontWeight="light" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearfirst"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_marginBottom="2dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/password_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
>
<android.support.v7.widget.AppCompatEditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:hint="password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
我的 Android 应用程序中有一个布局文件,如下所示;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/myPage"
android:theme="@style/login"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:id="@+id/myimageview"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:src="@drawable/mypicture"/>
<com.myapp.RobotoTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/myimageview"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="@string/mystring"
android:textColor="#fff"
android:textSize="12sp"
app:rt_fontWeight="light" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/password_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
app:theme="@style/loginTheme">
<android.support.v7.widget.AppCompatEditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:hint="@string/password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</RelativeLayout>
我想把 space 放在包含 RobotoTextView
的 RelativeLayout 和下面的 LinearLayout 之间layout.They 在我的布局中处于同一级别 file.Also 我的应用程序必须 运行 在不同的屏幕分辨率下。
一定是这个文本视图下的RobotoTextView和LinearLayout之间的约束之类的东西。
我在 LinearLayout 中尝试了 android:layout_marginTop
但它没有用。 RobotoTextView与LinearLayout
将此属性添加到底部布局,为其指定一个 id:
android:id="@+id/bottom"
还有这些到顶部布局:
android:layout_marginBottom="10dp"
android:layout_alignParentTop="true"
android:layout_above="@+id/bottom"
您可以将 10dp
更改为您喜欢的任何内容。
同时删除
android:layout_weight="1"
因为它仅适用于 LinearLayout
你没有解释好,但是,我按照你的指示尽力了。
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/myPage"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/linearfirst">
<ImageView
android:id="@+id/myimageview"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
<com.myapp.RobotoTextView
android:layout_width="159dp"
android:layout_height="51dp"
android:layout_below="@+id/myimageview"
android:layout_alignStart="@+id/myimageview"
android:layout_alignLeft="@+id/myimageview"
android:layout_alignEnd="@+id/myimageview"
android:layout_alignRight="@+id/myimageview"
android:layout_marginStart="-15dp"
android:layout_marginLeft="-15dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="-23dp"
android:layout_marginRight="-23dp"
android:gravity="center"
android:text="@string/mystring"
android:textColor="#fff"
android:textSize="12sp"
app:rt_fontWeight="light" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearfirst"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:layout_marginBottom="2dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/password_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
>
<android.support.v7.widget.AppCompatEditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:hint="password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>