android listview中getView重复被调用的问题
getView被调用的次数取决于当前屏幕能显示的item的数量,显示一个item就调用一次。当listview的layout_height属性是wrap_content时,有可能造成listview无法计算高度,相应的需要显示的item数量就无法计算,造成getView多次被调用。
解决方案:
1:
在listview外面套一层RelativeLayout,将listview高度设置为fill_parent。
<RelativeLayout xmlns:andro android: android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/repeat_bg"> <ListView android: android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:cacheColorHint="#00000000" android:divider="#CCCCCC" android:fastScrollEnabled="true" android:focusableInTouchMode="true" /> </RelativeLayout>
2:在listview外面套一层 LinearLayout,将listview高度设置为0dip。
<LinearLayout xmlns:andro android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#f3f3f3" android:orientation="vertical" > <ListView android: android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:cacheColorHint="#00000000" android:divider="#CCCCCC" /> </LinearLayout>
最后更新:2017-04-04 07:03:06
上一篇:
解决linux下无法添加用户和组的问题(groupadd命令不可用)
下一篇:
Android开发21——隐式意图
mysql
宣城市加快运用大数据推动全域旅游发展
一个程序员的哲学思考(关于编程、关于人生)
JSP中报错only a type can be imported: XXX resolves to package
《Servlet、JSP和Spring MVC初学指南》——2.2 隐藏域
日志服务(原SLS)发布:仪表盘(Dashboard)功能
J2EE中使用jstl报http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar错
NYOJ714-Card Trick
MySQL与MongoDB的操作对比
Edittext监听动态改变