3

I use several tiled drawables that are used as backgrounds for various layouts. For the most part the tiles work correctly but occasionally (once on every 4..5 runs) in some (but not all) of the backgrounds a single tile image gets stretched to fill in the background rather than repeat it (resulting in a very "fuzzy" background).

Tiles are declared in an xml drawable like this:

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

The tile drawable is used as a background image like this:

` RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/my_background_tile" >
`
....
/RelativeLayout>

This issue happens across multiple versions of Android and on different devices so there must be a trick to how to use tiles. Does anyone have experience using tile backgrounds or knows a workaround to force tiles to always repeat?

StefanK
  • 2,020
  • 2
  • 14
  • 16
  • This seems to be a bug (which I experienced myself). Did you take a look at [Tiled drawable sometimes stretches](http://stackoverflow.com/questions/4336286/tiled-drawable-sometimes-stretches)? – Knickedi Nov 07 '11 at 01:19
  • Thanks for the link. (Not sure why I did not find it when I searched before posting). From my (empirical) tests it seems like the Tile flags are (randomly) getting reset when the bitmap is inflated from the resources. As a workaround I end up "force setting" them by explicitly by calling setTileMode(TileMode.REPEAT, TIleMode.REPEAT) on my tiled background drawables after they are inflated. So far this seems to be working well. – StefanK Nov 08 '11 at 13:06

0 Answers0