Florian Mac Langlade
Florian Mac Langlade

Reputation: 1903

FrameLayout : Fill empty space

I have 3 FrameLayout in my layout, the first and the third have a fixed height (wrap_content of child views).

And I want the second FrameLayout to fill remaining space between the first and the third element.

My XML :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal" >

    <!-- ... childs views with fixed height -->
</FrameLayout>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" <!-- Fill remaining space -->
    android:layout_marginBottom="5dp"
    android:layout_marginTop="5dp" >

    <!-- ... childs views with match_parent height -->
</FrameLayout>

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

    <!-- ... childs view with fixed height -->
</FrameLayout>

</LinearLayout>

Upvotes: 4

Views: 2647

Answers (1)

Blackbelt
Blackbelt

Reputation: 157437

you can use the layout_weight="1" property for the central FrameLayout, leaving 0dip for the height. It will the take the space left from the other two

Upvotes: 4

Related Questions