【发布时间】:2011-09-14 06:59:02
【问题描述】:
这是我的自定义选择器 (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 的单元格并猜猜是什么时,有什么令人惊讶的?一切都很好,它应该是重复的。我不知道问题出在哪里,为什么我的背景不重复而突出显示。有什么想法吗?
【问题讨论】:
-
这里有同样的问题。似乎是随机的:有时位图会正确重复,有时会被拉伸
-
这里有同样的问题。使我抓狂。如果您找到解决方案,请发布解决方案。谢谢你!
-
@a.ch.请发表您的评论作为答案,我将其标记为正确。
标签: android xml bitmap repeat statelist