Android BitmapDrawable setTileModeX not working in TextView

I have a TextView and a bitmap that can only be repeated horizontally. I want to set the background of my text and repeat it only along the X axis. Looking around, I saw that you can only do this with code, not XML. I created 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 method, pulling is also repeated along the Y axis. This is in Honeycomb 3.2.

Can someone shed light on this, maybe an example of his work?

+6
source share
1 answer

//try it

 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. 
+1
source

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


All Articles