I have a TextView
and a bitmap that can be repeated only horizontally. I want to set the background of my textview and repeat it only on the X axis. After looking around I saw that you can only do that via code and not in XML. I created a BitmapDrawable
using:,
BitmapDrawable bg = new BitmapDrawable(r, BitmapFactory.decodeResource(r, R.drawable.my_drawable));
bg.setTileModeX(Shader.TileMode.REPEAT);
setBackgroundDrawable(bg);
However, even with this way the drawable is also repeated on the Y axis. This is in Honeycomb 3.2.
Can someone shed some light on this, perhaps provide an example of it working?
//try this
BitmapDrawable bg = new BitmapDrawable(r, BitmapFactory.decodeResource(r,R.drawable.my_drawable));
int width = view.getWidth();
int intrinsicHeight = bd.getIntrinsicHeight();
Rect bounds = new Rect(0,0,width,intrinsicHeight);
bg.setTileModeX(Shader.TileMode.REPEAT);
bg.setBounds(bounds);
Bitmap bitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), bg.getBitmap().getConfig());
Canvas canvas = new Canvas(bitmap);
bg.draw(canvas);
BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
yourTxtView.setBackgroundDrawable(bg);
// try this too
bg.setTileModeX(1); //Repeats the bitmap in both direction.
bg.setTileModeY(-1);//Do not tile the bitmap. This is the default value.
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