ListView背景奇怪地缩放

时间:2013-06-09 13:31:29

标签: android android-layout android-listview expandablelistview

我想将自定义背景应用于我的ExpandableListView。 ExpandableListView位于slidingMenu。

以下是样式:

<style name="Widget.SlidingMenu.ExpandableListView" parent="android:Widget.ExpandableListView">
    <item name="android:background">@drawable/sliding_menu_background</item>
    <item name="android:cacheColorHint">@android:color/transparent</item>
    <item name="android:divider">@drawable/menu_divider</item>
    <item name="android:childDivider">@drawable/menu_divider</item>
    <item name="android:dividerHeight">4px</item>
</style>

这是背景图片:

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/menu_noise"
        android:tileMode="repeat"
        android:dither="true"
        />

但问题是有时我的背景会像这样缩放并重复: https://dl.dropboxusercontent.com/u/6129677/bad_bg.JPG

有时一切都很好: https://dl.dropboxusercontent.com/u/6129677/good_bg.JPG

以下是应该重复的背景: https://dl.dropboxusercontent.com/u/6129677/menu_noise.png

我无法理解这背后的问题是什么。 请给我一个线索。

1 个答案:

答案 0 :(得分:2)

这是旧版Android中的一个错误。解决此问题的最简单方法是从代码设置切片模式。创建ExpandableListView后,只需获取其背景可绘制并更改切片模式:

View myListView = findViewById(...);
((BitmapDrawable) myListView.getBackground()).setTileModeXY(
    Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);