调用 ondraw 后重置画布,然后再次在 android 中调用它
我有一个活动,在其 oncreate 事件中我启动一个从 xml 嵌入的自定义视图。视图的 on draw 方法根据主活动计算的 x,y 点绘制一条曲线。
绘制曲线后,我想将画布重置回原始屏幕,以便我可以再次调用 ondraw 来绘制曲线,这次使用不同的 xy 坐标值。这可以实现吗?我想做这7次。
I have an activity in whose oncreate event I start a custom view embedded from xml.The on draw method of the view draws a curve based on the x,y points calculated from the main activity.
Once the curve is drawn I want to reset the canvas back to the original screen, so that I can again call the ondraw for drawing the curve this time with different vale of x-y co-ordinates.Is this possible to achieve ?I want to do this 7 times.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您调用自定义视图的 invalidate() 方法。它会告诉您的视图自行重绘。因此,您可以做的是创建一个方法来更改这些 x 和 y 坐标,然后调用 invalidate 以便它将使用您的新值重新绘制它。
如果这就是您正在寻找的东西,我不是 100%,所以发布一些代码,我们可以看看我们可以提供什么帮助。
编辑:
在做了更多工作之后,我还发现 viewObject.postInvalidate() 也可以工作。就我正在做的事情而言,效果更好!
If you call your custom view's invalidate() method. It will tell your view to redraw itself. So what you can do, is create a method that changes those x and y co-ordinates, then call invalidate so that it will redraw it using your new vales.
I am not 100% if this is what you are looking for, so post some code, and we can see what we can do to help.
EDIT:
After doing some more work, I have also found that viewObject.postInvalidate() works as well. In the case of what I am doing, it works better!
当您使用线程更新视图时,会使用 postInvalidate() 方法。
postInvalidate() method is used when you update your View with Thread.