I have an image that I want to tile horizontally and I need it done programmatically. I have tried two ways, and both do not work.
button_inner_shadow is the image navigation_background is the xml that suppose to tile the above image
1: tile image directly
BitmapDrawable navigationBackground = new BitmapDrawable(BitmapFactory.decodeResource(
getResources(), R.drawable.button_inner_shadow));
navigationBackground.setTileModeX(Shader.TileMode.REPEAT);
navigationTextViews[id].setBackgroundDrawable(navigationBackground);
2: use xml to tile image
navigationBackground = new BitmapDrawable(BitmapFactory.decodeResource(
getResources(), R.drawable.navigation_background));
navigationTextViews[id].setBackgroundDrawable(navigationBackground);
navigation_background
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true"
android:src="@drawable/button_inner_shadow"
android:tileMode="repeat" />
What am I doing wrong?
I also use setBackgroundResource
to set change the background color in another part of the program and thought that was a problem. I have added navigationTextViews[id].setBackgroundResource(0);
, which should remove the background resource, and that doesn't work with the above solutions I used.
EDIT: navigationTextViews[] is an array of TextViews
Well, for some reason, the first option worked with a different image, so I am guessing the problem is that my first image (which is a gradient with some transparency) was too transparent.
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