症状描述:
有些时候android:tileMode="repeat"这种样式的背景会莫名其妙的不起作用,背景图依然被拉伸而不是平铺。
解决方法:
调用函数,参数为要设置repeat背景的view
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);
}
}
}
参考:http://stackoverflow.com/questions/4077487/background-image-not-repeating-in-android-layout