在两个视图之间填充垂直 space (+scroll)

Fill vertical space between two views (+scroll)

我有 3 个观点。
1. View A 高度固定,与屏幕顶部对齐。
2. View B 有一个固定的高度并且对齐到屏幕的底部。
3. 视图 C 必须填充视图 A 和 B 之间的垂直 space,但必须是最小 X 高度。 如果A和B之间的垂直space小于Xdp,则必须出现垂直滚动条(视图B必须滚动,不能粘在底部)。

到目前为止我所知道的(有点简化),可能是完全错误的:

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fillViewport="true">

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

        <RelativeLayout
            android:id="@+id/layout_banner_top"
            android:layout_width="match_parent"
            android:layout_alignParentTop="true"
            android:layout_height="@dimen/statistics_probanner_height">

         </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" <!-- UPD here as McAdam331 suggested -->
            android:minHeight="@dimen/statistics_circular_progress_container_height"
            android:layout_below="@+id/layout_banner_top"
            android:layout_above="@+id/layout_banner_bottom">

            <!-- here is some content -->

         </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/statistics_bottom_bar_height"
            android:id="@+id/layout_banner_bottom"
            android:layout_alignParentBottom="true">

        </RelativeLayout>
    </RelativeLayout>
</ScrollView>

外观:
Picture 1
Picture 2

目前中间视图(视图 C)的最小高度设置为 600dp,但是正如您在图 2 中看到的那样,视图 C 正在填充顶部和底部视图之间的可用 space,高度太小并且滚动没有出现。

是否可以实施?我怎样才能实现这种行为?

问题是您将高度和最小高度设置为相同的值:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="@dimen/statistics_circular_progress_container_height"
    android:minHeight="@dimen/statistics_circular_progress_container_height"
    android:layout_below="@+id/layout_banner_top"
    android:layout_above="@+id/layout_banner_bottom">

换句话说,视图不会超过您已经指定的高度。我要做的是将 layout_height 设置为 wrap_content,并保持 min_height 属性不变。

这样,如果 space 大于给定的尺寸,它只会绑定在横幅的上方和下方。否则,它将保持该最小值。

已解决。

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fillViewport="true">

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/statistics_probanner_height"
            android:gravity="top">

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:minHeight="@dimen/statistics_circular_progress_container_height">

        </RelativeLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/statistics_bottom_bar_height"
            android:layout_gravity="bottom">
        </LinearLayout>

    </LinearLayout>
</ScrollView>