这是我的自定义选择器(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,猜猜发生了什么?一切都很好,它像应该一样重复了。我不知道问题出在哪里,为什么我的背景不会像高亮色一样重复。有什么想法吗?