NestedScrollView 的 子布局不能撑满整个屏幕,而是包裹内容,按照wrap_content来计算,哪怕写的 match_parent 也没用;
解决办法:
添加属性:
android:fillViewport="true"
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
.....
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
android:fillViewport="true"不生效
有时候这个属性可能不起作用,导致内容无法填充整个区域。本文将介绍一种解决这个问题的方法。
解决步骤
下面是解决android:fillViewport="true"不生效的步骤概览:
步骤 操作
1 确保ScrollView只有一个直接子View
2 检查ScrollView的父布局
3 检查子View的布局参数
4 使用代码设置android:fillViewport="true"
步骤1:确认ScrollView只有一个直接子View
ScrollView只能有一个直接子View,如果有多个子View,则需要将它们放入一个容器中。确保ScrollView只有一个直接子View的布局文件示例如下:
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
.....
</LinearLayout>
</android.support.v4.widget.NestedScrollView>