2012-05-23 20 views
6

Tengo un TextView y un mapa de bits que se puede repetir solo horizontalmente. Quiero establecer el fondo de mi vista de texto y repetirlo solo en el eje X. Después de mirar alrededor vi que solo puedes hacer eso por código y no en XML. Creé una BitmapDrawable usando :,Android BitmapDrawable setTileModeX no funciona en TextView

BitmapDrawable bg = new BitmapDrawable(r, BitmapFactory.decodeResource(r, R.drawable.my_drawable)); 
bg.setTileModeX(Shader.TileMode.REPEAT); 
setBackgroundDrawable(bg); 

Sin embargo, incluso con esta forma el dibujable se repite también en el eje Y. Esto está en Honeycomb 3.2.

¿Alguien puede arrojar algo de luz sobre esto, tal vez proporcionar un ejemplo de que funcione?

+0

Puede crear una dibujable mapa de bits que se refiere a su imagen actual y establece el atributo TILEMODE. –

+0

No entiendo lo que quieres decir ... – dnkoutso

Respuesta

1

// probar esto

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); 

// tratar esto también

bg.setTileModeX(1); //Repeats the bitmap in both direction. 
bg.setTileModeY(-1);//Do not tile the bitmap. This is the default value. 
Cuestiones relacionadas