Java – Android – Set up TileMode and Gravity

Android – Set up TileMode and Gravity… here is a solution to the problem.

Android – Set up TileMode and Gravity

I have a ListView with an XML layout. I want to set a new background for this View with the following code:

BitmapDrawable TileMe = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.bg_skyline));
TileMe.setGravity(Gravity.BOTTOM);  Bottom
TileMe.setTileModeX(Shader.TileMode.REPEAT);
ListView test = getListView();
test.setBackgroundDrawable(TileMe);

The problem is that if I uncomment both the Gravity and TileMode lines, only the TileMode will work. If I comment on the TileMode line, the Gravity line will work.

Am I doing something wrong or is something wrong with Android?

Solution

Gravity is ignored when tiling mode is enabled. Link

Related Problems and Solutions