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

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




版权声明:本文为qq_37077360原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。