Jim
Jim

Reputation: 19582

How to place 2 views to the bottom of the parent but one stacked above the other?

In a RelativeLayout if a view has android:layout_alignParentBottom="true” then it is placed to the bottom of the parent.
If 2 views have android:layout_alignParentBottom="true” then both are placed on the bottom, but 1 above the other.
How can I have 2 view to have the setting android:layout_alignParentBottom="true” and one to be stacked over the other?
android:layout_above seems to be not applicable/working for this case.

Upvotes: 0

Views: 176

Answers (3)

Szymon Klimaszewski
Szymon Klimaszewski

Reputation: 940

They won't be placed one after another if you have set only android:layout_alignParentBottom="true”. Please paste your layout xml so that the real issue can be found.

Upvotes: 0

Mikelis Kaneps
Mikelis Kaneps

Reputation: 4584

Put the views inside a LinearLayout with orientation - vertical, and put

layout_alignParentBottom=true

To the LinearLayout;

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

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

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

</RelativeLayout>

enter image description here

Upvotes: 2

Travis
Travis

Reputation: 3757

layout_above means "above" in a Y direction, not in a Z direction, if that makes sense. If you want them to overlay, remove the layout_above attribute and make them both layout_alignParentBottom=true.

Upvotes: 0

Related Questions