瓷砖绘制有时会延伸 [英] Tiled drawable sometimes stretches
问题描述
我有一个ListView的项目有一个平铺背景。要做到这一点,我用下面绘制的xml:
I have a ListView whose items have a tiled background. To accomplish this, I use the following drawable xml:
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/tile"
android:tileMode="repeat" />
通常情况下,这个工程。但是,有时在src绘制不是平铺,而是延伸至整个列表项。 (我有几个不同的瓷砖这样的,我用它们混合在一个ListView中,如果有拉伸,而不是平铺,它从来没有在所有的人一下子,什么是值得。)
Usually, this works. Sometimes, however, the src drawable isn't tiled, but stretched to fill the entire list item. (I've got several different tiles like this, and I use them mixed in one ListView. If there is stretching instead of tiling, it's never been in all of them at once, for what that's worth.)
我也尝试添加安卓抖动=真正的
到XML,因为我读的地方,没有它可能存在错误。这并没有改变任何东西。
I also tried to add android:dither="true"
to that xml, since I read somewhere that without it there might be bugs. That didn't change anything.
有没有人有同样的问题?你是怎么解决的呢?
Has anyone had the same problem? How did you fix it?
推荐答案
我也得到了咬了这个问题。非常难以诊断,甚至难以找到类似的报告和可用的解决方案。
I also got bitten by this problem. Very hard to diagnose, even harder to find similar reports and usable solutions.
小吃就在freenode#Android的开发IRC频道附带以下实用的方法:
"Tapas" on the freenode #android-dev irc channel came with the following utility method:
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);
}
}
}
将其应用到所有具有瓷砖后台设置视图(如findViewById他们)。
Apply it to all Views that have a tiled background set (e.g. findViewById them).
另外,我有IM pression这个bug开始设置后演戏anyDensity =真在AndroidManifest.xml中
Also, I have the impression this bug started acting up after setting "anyDensity=true" in AndroidManifest.xml
这篇关于瓷砖绘制有时会延伸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!