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監聽動態改變