Подтвердить что ты не робот

Android: поместите элемент под другим элементом и выровняйте внизу экрана

Я пытаюсь определить макет, где ImageView выравнивается в нижней части экрана, а также под GridView, чтобы избежать перекрытия.

Это приводит к тому, что ImageView устанавливается как раз под GridView, но не выравнивается в нижней части экрана.

Можно ли это решить с помощью другого вида макета?

<?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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/background"
    android:orientation="vertical">

    <RelativeLayout 
        android:id="@+id/gs_top_text_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:paddingBottom="30dp">

        <RelativeLayout 
            android:id="@+id/gs_top_sub_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:paddingBottom="30dp">

            <TextView
                android:id="@+id/text_l"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"/>

            <TextView
                android:id="@+id/text_t"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"/>

        </RelativeLayout>

        <RelativeLayout 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/gs_top_sub_container"
            android:layout_centerHorizontal="true">

            <TextView
                android:id="@+id/text1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

            <TextView
                android:id="@+id/text2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/text1"/>

        </RelativeLayout>



    </RelativeLayout>



    <GridView
        android:id="@+id/gs_grid_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/gs_top_text_container"
        android:descendantFocusability="blocksDescendants"
        android:horizontalSpacing="2dp"
        android:verticalSpacing="2dp"
        android:numColumns="3"
        android:gravity="center"
        android:paddingBottom="10dp"
        android:paddingTop="10dp" />


    <ImageView
        android:id="@+id/gs_bottom_logo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/gs_grid_view"
        android:layout_alignParentBottom="true"
        android:adjustViewBounds="true"
        android:maxWidth="200dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"/>

</RelativeLayout>
4b9b3361

Ответ 1

Вот как я это сделал:

1 - Поместите ImageView в нижнюю часть 2 - Поместите GridView ВЫШЕ его.

<!-- First anchor this View to the bottom -->
<ImageView
    android:id="@+id/gs_bottom_logo"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:adjustViewBounds="true"
    android:maxWidth="200dp"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
/>
<!-- Then put this View ABOVE the ImageView -->
<GridView
    android:id="@+id/gs_grid_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/gs_top_text_container"
    android:layout_above="@id/gs_bottom_logo"
    android:descendantFocusability="blocksDescendants"
    android:horizontalSpacing="2dp"
    android:verticalSpacing="2dp"
    android:numColumns="3"
    android:gravity="center"
    android:paddingBottom="10dp"
    android:paddingTop="10dp"
/>

Таким образом, я использовал относительность элементов в RelativeLayout

[EDIT]

Просто для удовольствия... Я оптимизировал ваш полный план.
Обратите внимание, как достигается тот же дизайн, используя много макетов меньше.

<?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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/background"
    >
    <TextView
        android:id="@+id/text_l"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:paddingBottom="30dp"
    />
    <TextView
        android:id="@+id/text_t"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:paddingBottom="30dp"
    />
    <!--
        This container is (unfortunately) still needed, to make these two
        textViews horizontally centered... :(
    -->
    <RelativeLayout
        android:id="@+id/rlCentering"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/text_l"
        android:layout_centerHorizontal="true"
        android:paddingBottom="30dp"
        >
        <TextView
            android:id="@+id/text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        />
        <TextView
            android:id="@+id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/text1"
        />
    </RelativeLayout>

    <!-- First, anchor this View to the bottom -->
    <ImageView
        android:id="@+id/gs_bottom_logo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:adjustViewBounds="true"
        android:maxWidth="200dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
    />
    <!-- Then put this View ABOVE the ImageView -->
    <GridView
        android:id="@+id/gs_grid_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/rlCentering"
        android:layout_above="@id/gs_bottom_logo"
        android:descendantFocusability="blocksDescendants"
        android:horizontalSpacing="2dp"
        android:verticalSpacing="2dp"
        android:numColumns="3"
        android:gravity="center"
        android:paddingBottom="10dp"
        android:paddingTop="10dp"
    />
</RelativeLayout>

И это то, что я получил в Графическом редакторе (я поставил несколько изображений, которые у меня были, и некоторые тексты, чтобы идентифицировать TextViews):

enter image description here

Ответ 2

Решил его, поставив ImageView в RelativeLayout, установив элемент layout_below в элементе RelativeLayout и alignParentBottom ImageView:

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/gs_grid_view">
<ImageView
    android:id="@+id/gs_bottom_logo"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:adjustViewBounds="true"
    android:maxWidth="200dp"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"/>
</RelativeLayout>