这是我的自定义选择器(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 的单元格并猜猜是什么时,有什么令人惊讶的?一切都很好,它应该是重复的。我不知道问题出在哪里,为什么我的背景不重复而突出显示。有什么想法吗?