现在的位置: 首页 > 综合 > 正文

解决Android布局中ScrollView与ListView的冲突

2018年01月09日 ⁄ 综合 ⁄ 共 835字 ⁄ 字号 评论关闭

今天写一个成绩表的小程序添加一个ScrollView里面嵌套一个ListView(现在想有点二,ListView自带的有滚动效果的,但还是提出问题跟大家分享哈),碰到了一个问题,不论我的layout_height设置为fill_partent,但不管ListView中添加多少行数据,只能显示二行

翻了一下文档和百度了一下,还有我的QQ群主hellogv给我的提示:

 

Romain Guy write a little info about a ScrollView attribute that is missing  from documentation : android:fillViewport=”true” .
It must be set to ScrollView and has the following efect : when set to true, this attribute causes the scroll view’s child to expand to the height of the ScrollView if needed. When the child is taller than the ScrollView, the attribute has no effect.

当你想让一个高度值不足scrollview的子控件fillparent的时候,单独的定义android:layout_height=”fill_parent”是不起作用的,必须加上fillviewport属性,当子控件的高度值大于scrollview的高度时,这个标签就没有任何意义了。

 

解决的办法有2个 :

1.在ScrollView中添加一属性 android:fillViewport=”true” ,这样就可以让ListView全屏显示了 ;

2.指定ListView的高度 android:layout_height=”420dp” ;

 

修改后的效果

抱歉!评论已关闭.