標籤:android style blog http color os strong io
定義的getView執行多次的ListView布局:
[html] view plaincopy
- <ListView
- android:id="@+id/lv_messages"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_alignParentLeft="true"
- android:layout_below="@+id/linearLayout1"
- android:cacheColorHint="#0000"
- android:divider="#0000"
- android:dividerHeight="2dp"
- android:listSelector="#0000" >
- </ListView>
執行多次原因是因為每顯示一個VIew,它都去測量view的高度,執行measure方法,導致getView執行多次。
正確的布局:
[html] view plaincopy
- <ListView
- android:id="@+id/lv_messages"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_alignParentLeft="true"
- android:layout_below="@+id/linearLayout1"
- android:cacheColorHint="#0000"
- android:divider="#0000"
- android:dividerHeight="2dp"
- android:listSelector="#0000" >
- </ListView>
把width和height都設定成fill_parent,如果ListView有父布局,也把父布局的width和height設定成fill_parent,這樣就成功的解決了自訂配接器getView 執行多次的問題。
下面這3行可以解決ListView滑動變黑的問題:
[html] view plaincopy
- android:cacheColorHint="#0000"
- android:divider="#0000"
- android:listSelector="#0000"
希望可以協助到大家解決問題!