這是我的自定義選擇器(StateListDrawable)StateListDrawable和瓷磚位圖
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/common_cell_background" />
<item
android:state_pressed="true"
android:drawable="@drawable/common_cell_background_highlight" />
<item
android:state_focused="true"
android:drawable="@drawable/common_cell_background_highlight" />
<item
android:state_selected="true"
android:drawable="@drawable/common_cell_background_highlight" />
</selector>
兩者common_cell_background和common_cell_background_highlight是XML。下面的代碼:
common_cell_background.xml
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/common_cell_background_bitmap"
android:tileMode="repeat"
android:dither="true">
</bitmap>
common_cell_background_highlight.xml
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/common_cell_background_bitmap_highlight"
android:tileMode="repeat"
android:dither="true">
</bitmap>
位圖也完全一樣。高光只是輕一點,沒有其他區別。這兩個位圖都是PNG文件。
現在我設定
convertView.setBackgroundResource(R.drawable.list_item_background);
,這裏是問題。我的common_cell_background不重複,它被拉長了。但是當我觸摸我的列表背景的單元格時,會有什麼驚奇變成了common_cell_background_highlight,並猜測是什麼?一切都很好,它應該重複。我不知道問題出在哪裏,爲什麼我的背景不會重複,而突出顯示。有什麼想法嗎?
這裏同樣的問題。看起來像是隨機的:有時位圖會被正確地重複,有時它會延伸到 – iseeall
這裏同樣的問題。使我抓狂。請發佈解決方案,如果你找到一個。謝謝你! – dineth
請參閱:http://stackoverflow.com/a/7615120/1037294 –