Android:BitmapDrawable.Draw(Canvas) 似乎不起作用
我试图将 20x20 背景平铺到我的自定义视图上,但由于某种原因我也无法做到。
BitmapDrawable background;
background = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.back));
background.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
background.draw(canvas);
有谁知道为什么它不起作用?
I am trying to tile a 20x20 background onto my Custom View but for some reason I am unable too.
BitmapDrawable background;
background = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.back));
background.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
background.draw(canvas);
Does anyone have an idea why it isn't working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要将边界设置为图块的大小:将它们设置为要平铺的总面积。在你的情况下:
Don't set the bounds to the size of the tile: set them to the total area to be tiled. In your case:
您忘记给出可绘制边界。在绘制之前,您需要至少调用一次drawable.setBounds()。
You forgot to give your drawable bounds. You need to call drawable.setBounds() at least once before drawing it.
我似乎已经用以下代码解决了这个问题
,但我现在有自己的问题。画布上无法绘制任何内容?
I seem to have fixed this problem with the following code
But I have my own problem now. Nothing can be drawn to the canvas?