dnk*_*tso 6 android background android-layout android-xml
我有一个TextView
只能水平重复的位图.我想设置textview的背景并仅在X轴上重复它.环顾四周之后,我发现你只能通过代码而不是XML来实现.我创建了一个BitmapDrawable
使用:,
BitmapDrawable bg = new BitmapDrawable(r, BitmapFactory.decodeResource(r, R.drawable.my_drawable));
bg.setTileModeX(Shader.TileMode.REPEAT);
setBackgroundDrawable(bg);
Run Code Online (Sandbox Code Playgroud)
然而,即使采用这种方式,也可以在Y轴上重复绘制.这是在Honeycomb 3.2中.
有人可以对此有所了解,也许可以提供一个有效的例子吗?
//尝试这个
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);
Run Code Online (Sandbox Code Playgroud)
//也试试这个
bg.setTileModeX(1); //Repeats the bitmap in both direction.
bg.setTileModeY(-1);//Do not tile the bitmap. This is the default value.
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
675 次 |
最近记录: |