Android Layout - ограничение между RelativeLayout и LinearLayout с одним и тем же родителем - PullRequest
0 голосов
/ 28 октября 2018

У меня есть файл макета в моем приложении 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>

Я хочу поместить пробел между RelativeLayout , который содержит RobotoTextView и LinearLayout под этим макетом. Они находятся на одном уровне в моем файле макета. Также мое приложение должно работать на разных разрешениях экрана.

Это должно быть что-то вроде ограничения между RobotoTextView и LinearLayout в этом текстовом представлении.

Я попытался android:layout_marginTop в LinearLayout, но это не сработало. RobotoTextView перекрывается с текстовым представлением под LinearLayout

Ответы [ 2 ]

0 голосов
/ 28 октября 2018

Вы не очень хорошо объяснили, но я приложил все усилия согласно вашей Инструкции.

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>

0 голосов
/ 28 октября 2018

Добавьте этот атрибут в нижний макет, который присваивает ему идентификатор:

android:id="@+id/bottom"

, а в верхний макет:

android:layout_marginBottom="10dp"
android:layout_alignParentTop="true"
android:layout_above="@+id/bottom"

вы можете изменить 10dp на любое значениелайк.Также удалите

android:layout_weight="1"

, поскольку оно применяется только к представлениям внутри LinearLayout

...