Android背景图片重复变形

时间:2013-12-09 17:58:03

标签: android

我使用android:tileMode =“repeat”作为我的textview backgrnound。它是大约1px高度的图像,但重复在左侧,右侧变形。 谢谢你的帮助!

屏幕:http://i.stack.imgur.com/yCXSQ.png

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/chat_rep"
     android:dither="true" 
    android:tileMode="repeat" />

1 个答案:

答案 0 :(得分:1)

对每个具有背景的视图调用此函数:

public static void fixBackgroundRepeat(View view) {
    Drawable bg = view.getBackground();
    if (bg != null) {
        if (bg instanceof BitmapDrawable) {
            BitmapDrawable bmp = (BitmapDrawable) bg;
            bmp.mutate(); // make sure that we aren't sharing state anymore
            bmp.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
        }
    }
}

这是在这个问题上发布的答案: "Tiled drawable sometimes stretches"