Linearlayout выше Relativelayout (гравитационное дно) - PullRequest
0 голосов
/ 30 ноября 2018

Содержание макета не работает

Ниже приведен мой XML-код.Я хочу разместить часть линейного макета с серым цветом чуть выше основного изображения. Снимок экрана с моим кодом здесь .

В устройствах с соотношением сторон 16: 9 дизайн правильный, но в 18: 9 и 18,5: 9 серая часть находится на верхней стороне.

Текст темы и значок должны быть в верхней левой части основного изображения.

Дизайн, который я хочу здесь

Не обращайте внимания на верхнюю сторону.Снизу высота должна быть обернута размером изображения

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:background="@color/light_green"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/dark_green">

        <LinearLayout
            android:id="@+id/topLin"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:background="@color/grey"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/nameTxt"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginStart="10dp"
                android:ellipsize="end"
                android:gravity="center|start"
                android:maxLength="25"
                android:singleLine="true"
                android:text="Abin Stanly"
                android:textColor="@color/white"
                android:textStyle="bold" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:adjustViewBounds="true"
                android:src="@drawable/test" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignTop="@id/imageView"
                android:layout_marginStart="20dp"
                android:layout_marginTop="15dp">

                <ImageView
                    android:id="@+id/icon"
                    android:layout_width="@dimen/icon_height"
                    android:layout_height="@dimen/icon_height"
                    android:layout_gravity="center"
                    android:src="@drawable/ic_love" />

                <TextView
                    android:id="@+id/topicTxt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:gravity="center"
                    android:paddingEnd="10dp"
                    android:shadowColor="@color/grey"
                    android:shadowDx=".5"
                    android:shadowDy=".5"
                    android:shadowRadius="3.5"
                    android:text="Topic"
                    android:textColor="@color/white"
                    android:textStyle="bold" />


            </LinearLayout>

        </RelativeLayout>

    </LinearLayout>
</LinearLayout>

Ответы [ 3 ]

0 голосов
/ 30 ноября 2018

Я добавил weightSum к родителю LinearLayout, чтобы вы могли легко разделить экран в соответствии с вашими требованиями.

Назначено View android:layout_weight="3", чтобы он занимал 3/10 часть экрана,Вы можете изменить его в соответствии с тем, что вам нравится.

<?xml version="1.0" encoding="utf-8"?>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:background="@android:color/holo_green_light"
        android:orientation="vertical"
        android:weightSum="10"
        xmlns:android="http://schemas.android.com/apk/res/android">


        <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="3" 
            android:background="@android:color/holo_green_light"
            />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="7">



            <TextView
                android:id="@+id/nameTxt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:maxLength="25"
                android:padding="11dp"
                android:background="@android:color/darker_gray"
                android:text="Abin Stanly"
                android:textColor="@android:color/white"
                android:textStyle="bold" />

            <RelativeLayout
                android:id="@+id/RelativeLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/nameTxt"
                android:layout_alignParentBottom="true"

                >

                <ImageView
                    android:id="@+id/imageView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:scaleType="centerCrop"
                    android:src="@drawable/mobile_world" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignTop="@id/imageView"
                    android:background="@android:color/black"
                    android:padding="11dp"
                    >

                    <ImageView
                        android:id="@+id/icon"
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:layout_gravity="center"
                        android:src="@drawable/back_arrow" />

                    <TextView
                        android:id="@+id/topicTxt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="8dp"
                        android:gravity="center"
                        android:paddingEnd="10dp"
                        android:shadowColor="@android:color/darker_gray"
                        android:shadowDx=".5"
                        android:shadowDy=".5"
                        android:shadowRadius="3.5"
                        android:layout_gravity="center_vertical"
                        android:text="Topic"
                        android:textColor="@android:color/white"
                        android:textStyle="bold" />


                </LinearLayout>

            </RelativeLayout>

        </RelativeLayout>
    </LinearLayout>

Выход

Output Image

0 голосов
/ 30 ноября 2018

Проверьте это расположение:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_green_light">

    <TextView
        android:id="@+id/nameTxt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/imageView"
        android:background="@android:color/darker_gray"
        android:maxLength="25"
        android:padding="10dp"
        android:text="Abin Stanly"
        android:textColor="@android:color/white"
        android:textStyle="bold" />


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:scaleType="centerCrop"
        android:src="@drawable/test" />

    <TextView
        android:id="@+id/topicTxt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/imageView"
        android:layout_gravity="center_vertical"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:drawableStart="@drawable/ic_love"
        android:drawablePadding="10dp"
        android:gravity="center"
        android:paddingEnd="10dp"
        android:shadowColor="@android:color/darker_gray"
        android:shadowDx=".5"
        android:shadowDy=".5"
        android:shadowRadius="3.5"
        android:text="Topic"
        android:textColor="@android:color/white"
        android:textStyle="bold" />
</RelativeLayout>
0 голосов
/ 30 ноября 2018

Здесь основной макет равен RelativeLayout, и оба потомка layout_alignParentBottom="true"

Вы можете просто переключать дочерние макеты до тех пор, пока не получите нужный макет

Совет. Меньшее количество макетоввы используете, более быстрый рендеринг будет на медленных устройствах.

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/light_green">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/grey">
        <TextView
            android:id="@+id/nameTxt"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginStart="10dp"
            android:ellipsize="end"
            android:gravity="center|start"
            android:maxLength="25"
            android:singleLine="true"
            android:text="Abin Stanly"
            android:textColor="@color/white"
            android:textStyle="bold" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
        <ImageView
            android:id="@+id/icon"
            android:layout_width="@dimen/icon_height"
            android:layout_height="@dimen/icon_height"
            android:layout_gravity="center"
            android:src="@drawable/ic_love" />
    </LinearLayout>
</RelativeLayout>
...