【发布时间】:2015-05-07 05:28:22
【问题描述】:
我有 3 个视图。
1. 视图 A 具有固定高度并与屏幕顶部对齐。
2. View B 具有固定高度,并与屏幕底部对齐。
3. 视图 C 必须填充视图 A 和 B 之间的垂直空间,但必须是最小 X 高度。 如果 A 和 B 之间的垂直间距小于 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>
当前,中间视图(视图 C)的 minHeight 设置为 600dp,但正如您在图 2 中看到的那样,视图 C 正在填充顶部和底部视图之间的可用空间,高度太小并且不会出现滚动。
可以实现吗?我怎样才能实现这种行为?
【问题讨论】:
-
视图 C 的高度应为
match_parent,以填充视图 A 和 B 之间的剩余空间。 -
@DerGolem 你是对的,这是在发布问题之前进行的一些实验。解决了这个问题,但它当然不起作用。视图 A 和 B 之间的空间正在填充,但 minHeight 和 scroll 似乎不起作用。
-
600dp似乎有点过分了。特别是在水平模式下。 -
仅用于测试目的,以确保滚动条按预期显示并且视图的高度为 minHeight。
标签: android android-layout views