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

问题描述 投票:19回答:1

我在我的片段中使用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>

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

提前致谢

android android-scrollview android-relativelayout android-nestedscrollview
1个回答
61
投票

尝试在nestedscrollview上添加这行代码

android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"

去掉:

android:fitsSystemWindows="true"
© www.soinside.com 2019 - 2024. All rights reserved.