I'm trying to create a tiled background for a match_parent
-wide container, where the tile is repeated from the parent's center, not from its left edge. I want this in order for the background to always appear centered regardless of screen width.
I noticed that Android's BitmapDrawable
has a gravity
attribute, but it seems to have no effect when tileMode
is set to repeat
or mirror
. I would have expected that the bitmap is first centered in its container, then repeated outwards from the center point. Instead, it's still left-aligned and then repeated, resulting in the first tile always be fully visible but the last tile being cut off unless the screen width is a multiple of the tile's width.
UPDATE: Just noticed, "Gravity is ignored when the tile mode is enabled." (tileMode attr docs.) Any other ways to achieve this?
I think this post might be interesting to you. Basically gravity doesn't work with tilemode (as we've already established) but you could create a matrix of your images and use that to create the background of your desire. So basically build the tilemode in code yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With