在 onDraw() 中调用 invalidate() 是一个好的编程习惯吗?

发布于 2024-10-17 10:06:30 字数 297 浏览 9 评论 0原文

  1. onDraw() 内调用 invalidate() 是一个好的编程习惯吗?

根据我的理解,在 onDraw() 内部调用 invalidate() 的成本很高,如果画布没有发生变化,则不需要。

  1. invalidate() 是否等同于 onDraw() 的异步版本?

根据我的理解,它们是等价的。如果我错了请纠正我。谢谢。

  1. Is it a good programming practice to call invalidate() inside onDraw()?

As per my understanding, calling invalidate() inside onDraw() is expensive and is not required if there is no change to the canvas.

  1. Is invalidate() equivalent to an asynchronous version of onDraw()?

As per my understanding, they are equivalent. Correct me if I am wrong. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甩你一脸翔 2024-10-24 10:06:30

仅当您的数据已更改且需要重新绘制时才调用 invalidate()。您通常不会在 onDraw() 中执行此操作,因为此时您正在绘制当前数据,而不是更改它。 (在某些情况下,您可能想要这样做,例如运行动画,但通常我会建议使用延迟消息来控制您自己的更新时间。)

Only call invalidate() if your data has changed and needs to be redrawn. You generally don't do this in onDraw(), because at that point you are drawing your current data, not changing it. (There are some cases where you may want to do this, such as for running animations, but generally I would recommend instead using a delayed message to control your own timing of the updates.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文