ScrollView中子项设置match_parent失效,无法铺满全屏

来源:互联网 发布:四川省广电网络官网 编辑:程序博客网 时间:2024/06/07 20:02

ScrollView中子控件设置match_parent失效,无法占满全屏

1、测试验证:

<ScrollView ....><LinearLayout ...>..........<LinearLayout  android:layout_width="match_parent"               android:layout_height="match_parent"android:background="@color/cef">.....</LinearLayout></LinearLayout></ScrollView>


当我们设置背景颜色时,可以清楚的看到剩余空间并没有都设置为上面的背景色

2、 方法:

ScrollView设置如下属性:

android:fillViewport="true"

引用一下别人的解释:

    当ScrollView没有fillVeewport=true”时,里面的元素(比如LinearLayout)会按照wrap_content来计算(不论它是否设了"fill_parent"),而如果LinearLayout的元素设置了fill_parent,那么也是不管用的,因为LinearLayout依赖里面的元素,而里面的元素又依赖LinearLayout,这样自相矛盾.所以里面元素设置了fill_parent,也会当做wrap_content来计算.


参考链接:

https://www.cnblogs.com/tony-yang-flutter/p/3740902.html



阅读全文
0 0
原创粉丝点击