Android onDraw方法
在 onDraw(Canvas canvas1) 方法中,我看到如何使用传递的参数“canvas1”来绘制形状。但是,如果我要创建一个新的 Canvas 对象示例“:
Canvas canvas2 = new Canvas();
Paint paint = new Paint();
paint.setColor(Color.BLUE);
canvas2.drawRect(55,87,130,600, paint);
canvas2不会显示在屏幕上,我怎样才能让它与canvas1对象一起显示?
in the onDraw(Canvas canvas1) method i see how it is possible to draw shapes using the passed argument of "canvas1". However, if i were to create a new Canvas object example":
Canvas canvas2 = new Canvas();
Paint paint = new Paint();
paint.setColor(Color.BLUE);
canvas2.drawRect(55,87,130,600, paint);
canvas2 won't be displayed on screen, how can i get it displayed together with the canvas1 object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你想画图层吗?也许您需要使用带有两个子视图的视图组,例如 FrameLayout :一个使用canvas1,另一个使用canvas2。
Are you trying to draw layers? Perhaps you need to use a viewgroup such as FrameLayout with two children views: one using canvas1, the other using canvas2.
当您使用 Canvas() 构造函数创建画布时,您会得到一个空的光栅画布。
根据文档:
这意味着除非您明确地将位图附加到 Canvas 对象,否则您的绘图将被丢弃。
When you create canvas using
Canvas()
constructor, your get an empty raster canvas.As per documentation:
This means that your drawings are just thrown away unless you explicitly attach bitmap to
Canvas
object.我正在使用在 FrameLayout 中渲染的自定义 ImageView,正如我在 这个线程中解释的那样。
I'm using custom ImageViews rendered in a FrameLayout as I explained in this thread.