FrameLayout:填充空白区域

时间:2014-06-02 12:17:11

标签: android android-layout

我的布局中有3 FrameLayout,第一个和第三个都有固定的高度(子视图的wrap_content)。

我希望第二个FrameLayout填充第一个和第三个元素之间的剩余空间。

我的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>

1 个答案:

答案 0 :(得分:2)

您可以将layout_weight="1"属性用于中央FrameLayout,将0dip留给height。这将占用其他两个空间