TaLha Khan
TaLha Khan

Reputation: 2433

Using RelativeLayout to make a View take all remaining space

I want to achieve this

required

I am doing this

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:id="@+id/upper"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/wallet_dim_foreground_inverse_disabled_holo_dark">
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:orientation="horizontal"
        android:layout_below="@+id/upper"
        android:background="@color/blueAccentColor">
    </LinearLayout>
</RelativeLayout>

Upvotes: 0

Views: 61

Answers (2)

Pier Giorgio Misley
Pier Giorgio Misley

Reputation: 5351

You have to set the first Layout to be above the seconde.

With the code you provided you will have a top layout taking all space, and a bottom layout being below him. If you think about it you can see that it's logic that the result will be different.

If you remove android:layout_below="@+id/upper"and add android:layout_alignParentBottom="true"from the lower one, this Layout will be anchored to the bottom side, whichever the screen size is.

Than adding android:layout_above="@+id/lower" to the top Layout, he will take all space(thanks to android:layout_height="fill_parent") but it will stay above the lower Layout.

Here is the result you want :)

Upvotes: 1

Carnal
Carnal

Reputation: 22064

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:id="@+id/upper"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/lower"
        android:background="@color/wallet_dim_foreground_inverse_disabled_holo_dark">
        </LinearLayout>
    <LinearLayout
        android:id="@+id/lower"
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:background="@color/blueAccentColor"></LinearLayout>
    </RelativeLayout>

Upvotes: 2

Related Questions