在两个工具栏之间拉伸布局的最聪明的方法是什么?

What is the smartest way to stretch a layout between two toolbars?

这是我的代码。工具栏有固定的位置。你如何在它们之间实现拉伸中间布局(grid/listview)?

提前致谢。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<include layout="@layout/toolbar"
    android:id="@+id/top_toolbar"/>

<RelativeLayout
    android:id="@+id/ll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_alignTop="@+id/top_toolbar">

    <GridView
        android:id="@+id/gv_grid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:numColumns="auto_fit" />

    <ExpandableListView
        android:id="@+id/id_list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:descendantFocusability="blocksDescendants"
        android:visibility="gone"/>

</RelativeLayout>

<include layout="@layout/bottom_toolbar"/>

我会将第一个 RelativeLayout 更改为 LinearLayout,然后在第二个 RelativeLayout 中添加一个 android:layout_weight="1",如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<include layout="@layout/toolbar"
    android:id="@+id/top_toolbar"/>

<RelativeLayout
    android:id="@+id/ll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical"
    android:layout_alignTop="@+id/top_toolbar">

    <GridView
        android:id="@+id/gv_grid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:numColumns="auto_fit" />

    <ExpandableListView
        android:id="@+id/id_list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:descendantFocusability="blocksDescendants"
        android:visibility="gone"/>

</RelativeLayout>

<include layout="@layout/bottom_toolbar"/>