背景
ScrollView本身的高度设置为match_parent,其子View的高度也设置为match_parent,自然状态下该子View的高度并不会占满ScrollView的高度。
原因是match_parent针对一般布局而言,是子view的高度和parent的高度一致,但在ScrollView身上,工作机制并非如此,而是ScrollView的高度随着子View的高度变化而变化(子View高度大于ScrollView时)。在子View高度小于ScrollView高度时,必需在xml里为ScrollView加上android:fillViewport="true",这样子View小于ScrollView高度时就会占满父View.
解决方法
xml里为ScrollView加上android:fillViewport="true"
源码地址: https://github.com/HuaDanJson/NestedscrollRecyclerview
探讨了ScrollView在Android中如何实现子View填满整个视图的问题,解释了match_parent属性的工作机制,并提供了解决方案,即使用android:fillViewport=true。
707

被折叠的 条评论
为什么被折叠?



