android使位图在x中可绘制,但在y中不可绘制
我正在尝试使位图可绘制在x中重复平铺,对齐此可绘制视图底部(可用空间按颜色填充),这样我的可绘制视图就不会在y中倾斜。android使位图在x中可绘制,但在y中不可绘制,android,drawable,Android,Drawable,我正在尝试使位图可绘制在x中重复平铺,对齐此可绘制视图底部(可用空间按颜色填充),这样我的可绘制视图就不会在y中倾斜。 我没有达到目标 源背景图像: 在大屏幕上填充此图片上方可用空间的颜色:#FF5cc8f2 这是第一个变体: BitmapDrawable tile = (BitmapDrawable) res .getDrawable(R.drawable.background); tile.setTileModeX(Shader.TileMo
我没有达到目标 源背景图像:
在大屏幕上填充此图片上方可用空间的颜色:#FF5cc8f2 这是第一个变体:
BitmapDrawable tile = (BitmapDrawable) res
.getDrawable(R.drawable.background);
tile.setTileModeX(Shader.TileMode.REPEAT);
view.setBackgroundColor(res.getColor(R.color.background));
view.setBackgroundDrawable(tile);
结果:正如您所看到的,我在云层下面有不需要的空白。 第二种变体:
BitmapDrawable bd = (BitmapDrawable) res.getDrawable(R.drawable.background);
WindowManager wm = (WindowManager) AvApplication.getInstance().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int width;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
width = display.getWidth();
} else {
Point size = new Point();
display.getSize(size);
width = size.x;
}
int intrinsicHeight = bd.getIntrinsicHeight();
Rect bounds = new Rect(0,0,width,intrinsicHeight);
bd.setTileModeX(TileMode.REPEAT);
bd.setBounds(bounds);
Bitmap bitmap = Bitmap.createBitmap(bounds.width(), bounds.height(), bd.getBitmap().getConfig());
Canvas canvas = new Canvas(bitmap);
bd.draw(canvas);
BitmapDrawable bitmapDrawable = new BitmapDrawable(res, bitmap);
view.setBackgroundDrawable(bitmapDrawable);
BitmapDrawable bd=(BitmapDrawable)res.getDrawable(R.drawable.background);
WindowManager wm=(WindowManager)AvApplication.getInstance().getSystemService(Context.WINDOW\u服务);
Display Display=wm.getDefaultDisplay();
整数宽度;
if(Build.VERSION.SDK\u INT
结果:现在图像位于底部,但已拉伸 不要在意一个屏幕截图是横向的,第二个是纵向的——结果在两个方向都会被检查 我需要你的帮助。我会尝试:
BitmapDrawable tile = (BitmapDrawable) res.getDrawable(R.drawable.background);
tile.setTileModeX(Shader.TileMode.REPEAT);
tile.setGravity(Gravity.bottom)
tile.setTileModeY(Shader.TileMode.CLAMP);
// it replicates the edge color if the shader draws outside of its original bounds
//thus you don't even need to set a background color.
view.setBackgroundDrawable(tile);
谢谢你的回答,但结果与我的第一个案例相同。正如我所知,不幸的是,当瓷砖模式启用时,重力没有任何影响。哦,你是对的,看起来夹钳只用于底部和右侧。。。奇怪。