优化 Android 中的 onDraw - 哪个区域正在重绘?
在我的 Android 应用程序中,我有一个实现 onDraw() 的自定义视图。
我知道一种优化方法是对需要重绘的特定区域使用 invalidate(rect) 。同时,如果我知道 onDraw() 中需要重绘哪个区域,我可以进一步优化绘图。
对于 iPhone,我使用
- (void)drawRect:(CGRect)rect 方法,因此我知道无效的矩形(作为参数传递)。
Android 有什么方法可以得到这个矩形吗?
In my android app, I have a custom View implementing onDraw().
I know a way to optimize it is to use invalidate(rect) for specific area that needs to be redrawn. At the same time, I could optimize the drawing even further if I knew which area needs to be redrawn inside onDraw().
In case of iPhone, I am using
- (void)drawRect:(CGRect)rect method so I know the invalidated rectangle (which is passed as parameter).
Is there any way to get this rectangle in Android?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于任何感兴趣的人:
看起来canvas.getClipBounds()为我提供了onDraw()中的无效区域,尽管Android文档对此并不清楚。这个矩形也可以是(0,0,0,0),所以使用时要小心。
For anyone interested:
It looks like canvas.getClipBounds() gets me the invalidated area within onDraw(), even though Android documentation is not clear about it at all. This rectangle can also be (0,0,0,0) so be careful when using it.