Sometimes stretched tiles stretch

I have a ListView whose elements have a mosaic background. For this, I use the following drawable xml:

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

This usually works. Sometimes, however, src drawable is not engraved, but stretched to fill the entire list item. (I have several different such fragments, and I use them in the same ListView. If stretching instead of tiles, it was never in all at once what it's worth.)

I also tried adding android:dither="true" to this xml, as I read somewhere that there could be errors without it. This has not changed anything.

Has anyone had the same problem? How did you fix it?

+52
android xml drawable tiling
Dec 02 2018-10-12
source share
9 answers

I also bit this problem. It is very difficult to diagnose, it is even more difficult to find similar reports and useful solutions.

"Tapas" on the android-dev irc channel of the freenode channel appeared 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); } } } 

Apply it to all views that have a tile background set (for example, findViewById).

In addition, I get the impression that this error started to work after setting "anyDensity = true" in AndroidManifest.xml

+37
Feb 29 2018-12-12T00:
source share

I have only the same problem besides CLAMP TileMode. I have a bitmap that I want to just stretch to the bottom and set it up as an XML bitmad driver, and everything looks fine in the graphic viewer, no matter what size I do, ViewImage draws my bitmap at the top and then repeats The last pixels to be filled to the end.

Running the application on various SDK assemblies on the emulator and on my own phone still produced a direct “fill” type distortion, which is completely useless.

The solution turned out to be a simple re-application of TileMode every time I resized ImageView in my code:

 ((BitmapDrawable)ascender.getDrawable()).setTileModeY(TileMode.CLAMP); 

Now all this is wonderful. So yes, it looks like a mistake to me.

+9
May 01 '11 at 23:33
source share

Since I did not see the link here, it was confirmed as an error in Android. This was recorded in ICS. See the XML version of Bitmap tileMode for more details? .

+6
Jun 18 2018-12-18T00:
source share

There is a lot of noise in this topic, with various (and many) proposed solutions.

  • If you are still at a loss, my suggestion is to save all tiled bitmap resources to a square, base size-2 .

i.e.: 16px by 16px for the xhdpi tile element.

I was hoping the Android platform would be “interlaced” to fill in the gap if the bitmap wasn’t well tessellated, and then crop the waste. However, breaking through a 10px * 10px tile of a mdpi, hdpi and xhdpi (and v2.3 to v4.0) "inconsistently" showed this stretch.

The size of the base-2 allows for complete and even division when passing through various resolutions and when each device tries to draw tiles every time it creates a view.

In Android development, we dispute the ranking hardware and sellers diving into the platform - sometimes it's just trivial black magic working.

This seems to have solved the problem for me, at least. It’s worth taking a picture.

+6
Aug 02 '13 at 7:26
source share

It sounds like a mistake, although I never saw it myself. If you have a simple APK that reproduces the problem, send it to me (romainguy / at / android.com) or report an error here .

+2
Feb 15 '11 at 17:39
source share

This blog discusses the issue

coupled with this Tapas solution , pointed out by Ivo van der Wijk, it works for me.

The key was to remove the tiled parameter from XML, and then set it to a file at run time. This does not work for me if they are both installed in the tile.

Edit: Actually, I lied. Even with this, it seems sometimes the tiles fail.

It would be very nice to have a reliable job.

Edit 2: install it on something else (e.g. CLAMPED) and then install it back seems to work.

+1
May 01 '12 at 3:14
source share

Still suffering from this problem on older devices working with Lollipop, occurs when the orientation changes. Tile mode setting did not work programmatically, but this answer did: https://stackoverflow.com/a/2776262

0
Jun 07 '16 at 11:40
source share

I moved the image from drawable-xhdpi to the drawable folder and everything was fine.

0
Nov 24 '16 at 7:26
source share

I had the same problem too. What I was missing was that we needed to add a scaletype for fitXY to the imageview so that the xml bitmap would work correctly.

tile_bitmap.xml

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

layout.xml

 <ImageView android:layout_width="match_parent" android:src="@drawable/tile_bitmap" android:layout_height="match_parent" android:scaleType="fitXY"/> 
0
Oct 10 '17 at 9:29
source share



All Articles