NestedScrollView中的子视图未覆盖整个屏幕高度

51
我在我的片段中使用了NestedScrollView。在我的xml文件中,它位于RelativeLayout中,但它没有覆盖整个屏幕高度。
以下是我的代码 -
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:background="@color/black"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
    android:background="@color/red_error_color"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
当运行代码时,只能看到黑色背景,而不能看到红色,因为我的子视图背景是红色。
提前致谢。
1个回答

141
尝试在你的nestedscrollview上添加这行代码。
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"

删除:

android:fitsSystemWindows="true"

17
我认为在更一般的情况下,android:fillViewport="true" 就足够了。(对我有效) - Stan
无需添加kayout_behavior属性。 - Moustafa EL-Saghier

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接