填充布局直到下一个布局(在底部)

Fill with Layout until next layout (at bottom)

所以,我有一个页眉,然后是一个应该填满屏幕直到页脚的 CardView。问题是,它填满了整个屏幕,页脚 "under" 占据了屏幕,正如您在图像中看到的那样。

我想让页脚(按钮 + 两个图像)始终位于底部,而卡片视图应始终填满屏幕的其余部分。卡片视图中有一个滚动视图,允许在卡片视图中读取文本。

无论如何,这是XML代码:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_10">

    <View
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:background="@color/colorPrimary" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true"
        android:layout_marginBottom="@dimen/spacing_mlarge"
        android:orientation="vertical"
        android:padding="@dimen/spacing_mlarge">

    <TextView
        android:id="@+id/qstView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:layout_marginBottom="20dp"
        android:text="Insert question text here"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
        android:textColor="@color/white" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.CardView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginBottom="@dimen/spacing_middle"
            android:layout_marginEnd="@dimen/spacing_middle"
            android:layout_marginLeft="@dimen/spacing_middle"
            android:layout_marginRight="@dimen/spacing_middle"
            android:layout_marginStart="@dimen/spacing_middle"
            android:layout_marginTop="@dimen/spacing_middle"
            android:visibility="visible"
            app:cardCornerRadius="6dp"
            app:cardElevation="5dp">

            <ScrollView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                        android:id="@+id/checkbox_full_layout"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_margin="5dp"
                        android:orientation="vertical">

                    </LinearLayout>

                </LinearLayout>
            </ScrollView>

        </android.support.v7.widget.CardView>
    </LinearLayout>
    <Button
        android:id="@+id/add_field_button"
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:onClick="onAddAnswer"
        android:layout_gravity="bottom"
        android:layout_marginLeft="-4dp"
        android:layout_marginRight="-4dp"
        android:background="@drawable/btn_rounded_primary"
        android:text="Suivant"
        android:textAllCaps="false"
        android:textColor="@android:color/white"
        android:textStyle="bold" />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="@dimen/spacing_mlarge"
        android:layout_gravity="center_horizontal"
        android:gravity="center">
        <ImageView
            android:layout_width="80dp"
            android:layout_height="60dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="@dimen/spacing_mlarge"
            android:layout_marginTop="@dimen/spacing_large"
            android:src="@drawable/ineedhelp"/>
        <View
            android:layout_width="@dimen/spacing_large"
            android:layout_height="0dp" />
        <ImageView
            android:layout_width="80dp"
            android:layout_height="60dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginBottom="@dimen/spacing_mlarge"
            android:layout_marginTop="@dimen/spacing_large"
            android:src="@drawable/mbtouch_dark"/>
    </LinearLayout>
        <View
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginBottom="@dimen/spacing_middle"
            android:layout_alignParentBottom="true"/>
    </LinearLayout>
</RelativeLayout>

这是我目前拥有的:

这就是我想要的(这里我强制尺寸,但由于并非所有设备都相同,因此space将不会得到最佳使用).

提前致谢!

尝试按以下方式排列视图(对于CardView和底部布局,其余部分将保持原样)..

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    ....
    ...>

     <!--  Since, weight is 1 it will occupy whole space subtracting height of bottom  -->
     <CardView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        .... />

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ....>

        <!--  Put your bottom widgets over here  -->

    </LinearLayout>

</LinearLayout>