Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
invalidate()
onDraw()
据我了解,invalidate()内部调用onDraw()很昂贵,如果画布没有变化,则不需要。
根据我的理解,它们是等价的。如果我错了,请纠正我。谢谢你。
仅invalidate()当您的数据已更改并需要重绘时才调用。您通常不会在 中执行此操作onDraw(),因为此时您正在绘制当前数据,而不是更改它。(在某些情况下您可能想要这样做,例如运行动画,但通常我会建议您使用延迟消息来控制您自己的更新时间。)