How to center a background tile?

I am trying to create a tiled background for the match_parent -wide container, where the fragment repeats from the parent center, and not from its left edge. I want this so that the background is always displayed in the center regardless of the width of the screen.

I noticed that Android BitmapDrawable has a gravity attribute, but it doesn't seem to work if tileMode set to repeat or mirror . I would suggest that the bitmap is first centered in the container and then repeats outward from the center point. Instead, it is still left-aligned and then repeated, with the result that the first tile will always be fully visible, but the last fragment will be cropped if the screen width is not a multiple of the tile width.

UPDATE: Just noticed: "Gravity is ignored when tile mode is on." (tileMode attr docs.) Any other ways to achieve this?

+4
source share
1 answer

I think this post may be of interest to you. Basically, gravity does not work with tilemode models (as we already set), but you can create a matrix of your images and use it to create the background of your desire. So basically create a piece of code in the code.

+2
source

Source: https://habr.com/ru/post/1443979/


All Articles