NestedScrollView内的子节点不能覆盖屏幕的全高

Rav*_*ari 25 android android-scrollview android-relativelayout android-nestedscrollview

我在我的片段中使用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>
Run Code Online (Sandbox Code Playgroud)

在运行代码时,只有黑色背景可见但不是红色,因为我的子视图背景为红色.

提前致谢

Nci*_*mos 71

尝试在nestedscrollview上添加这行代码

android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
Run Code Online (Sandbox Code Playgroud)

去掉:

android:fitsSystemWindows="true"
Run Code Online (Sandbox Code Playgroud)

  • 我想在更一般的情况下android:fillViewport ="true"就足够了.(为我工作) (10认同)