scroll view 中嵌套listview gridview 时,listview gridview match_parent 无效

来源:互联网 发布:丹尼尔戴刘易斯 知乎 编辑:程序博客网 时间:2024/05/29 15:12

scroll view 中嵌套一个listview 或者gridview 时 listview(gridview) 沾满全部屏幕空间,一般表现状态为只显示一个item 的高度。 这时可以在scroll view xml 节点中配置attribute android:fillViewport="true"

该属性的作用为允许scrollview 的child view 修改scroll view 的高度。 那为什么在listview (gridview)中设置fill_parent or match_parent 不起作用呢?原因在于scrollview 的高度在计算时的确是只给listview (gridview)预留了一个item height 的空间。当listview (gridview)measure 时根据属性fill_parent or match_parent 他的确是只需要一个item height .


/** * When set to true, the scroll view measure its child to make it fill the currently * visible area. */@ViewDebug.ExportedProperty(category = "layout")private boolean mFillViewport;


原文解释:详见

 http://stackoverflow.com/questions/10211338/view-inside-scrollview-doesnt-take-all-place

0 0
原创粉丝点击