2012-05-23 1 views
6

TextView과 가로로만 반복 할 수있는 비트 맵이 있습니다. 내 textview의 배경을 설정하고 X 축에서만 반복하고 싶습니다. 주변을 둘러 본 후에 나는 XML이 아닌 코드를 통해서만이를 수행 할 수 있음을 확인했습니다. I 심지어 그리기 또한 Y 축에 반복된다 이런 방식으로, 그러나 Android BitmapDrawable setTileModeX가 TextView에서 작동하지 않습니다.

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

:를 이용 BitmapDrawable을 만들었다. 이것은 Honeycomb 3.2에 있습니다.

누군가이 문제에 대해 의견을 개진 할 수 있습니까?

+0

당신은 당신의 실제 이미지를 참조하고, TILEMODE 속성을 설정하는 비트 맵 드로어 블을 만들 수 있습니다하려고 시도합니다. –

+0

무슨 뜻인지 이해가 안 돼요 ... – dnkoutso

답변

1

//이

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

//이 너무

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