在一个布局中,分上下两层,如果想要使最下层wrap_content,上层占剩余的全部空间,就要让上层使用android:layout_height=”0dp”,android:layout_weight=”1”属性,下层使用android:layout_height=”wrap_content”属性。layout_weight=1是指该控件显示除去wrap_content控件所占大小的其他剩余空间,如果wrap_content中没有内容,那么layout_weight=1的控件占全部内容(三层也适用)
代码如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</FrameLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:layout_gravity="bottom">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical" >
<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:listSelector="@color/transparent_background">
</GridView>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
效果图如下: