安卓:无效(脏) [英] Android: invalidate(dirty)

查看:190
本文介绍了安卓:无效(脏)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好像还真的Andr​​oid不喜欢无效(矩形脏),这是用来无效画布的一部分。当我无效掉画布的一部分(示于下面绿色)和一个切换按钮的的帆布需要在同一时间被重绘,在以红色显示整个区域将被删除!它好像Android的仅仅是无效的最小矩形包含了需要重新绘制两个区域的联盟内的一切,即使区域之一是查看其画布我无效之外。

这是标准的行为,如果是这样,为什么会有人使用部分无效?

解决方案

Android有一类叫做 ViewRootImpl 。这个类是由你在屏幕上看到每个窗口拥有(术语窗口是有点混乱这里,所以对于这个解释一个窗口没有在上面任何对话框或弹出窗口的主要活动的布局)。 这种布局正在遍历所有的时间,这意味着Android的只是等待有一个肮脏的矩形窗口,并绘制它。由于这个窗口可以包含多个视图(按钮等),它通过所有的人,并要求每一个是否需要重新绘制。 每个视图返回一个肮脏的矩形 ViewRootImpl ,所有这些矩形加入到一个大的矩形重绘到底。

为什么会这样?好了, ViewRootImpl 询问 WindowManagerService 画布来画在。这意味着,在一个窗口中的所有观点实际上是共享一个画布每次有一种穿越。

至于你的问题,如果只有一个特定的查看有一个肮脏的矩形那么只有肮脏的矩形将被绘制,但由于另一种观点认为有一个还有那么脏矩形包含两个

It seems like Android really doesn't like invalidate (Rect dirty), which is used to invalidate only part of a canvas. When I invalidate part of a canvas (shown in green below) and a ToggleButton outside of the canvas needs to be redrawn at the same time, the entire region shown in red is erased! It seems as though Android is just invalidating everything within the smallest rectangle encompassing the union of the two regions that need to be redrawn, even if one of the regions is outside of the View whose canvas I'm invalidating.

Is this standard behaviour, and if so, why would anyone use partial invalidation?

解决方案

Android has a class called ViewRootImpl. This class is owned by every window you see on the screen (the term window is a little confusing here, so for this explanation a window is the main activity's layout without any dialogs or popups on top). This layout is being traversed all the time, meaning that Android is just waiting to have a dirty rectangle for this window and draw it. Since this window may contain many views (buttons etc.) it goes through all of them and asks each one whether it needs redrawing. Each view returns a dirty rectangle to ViewRootImpl and all these rectangles are joined to one big rectangle that is redrawn in the end.

Why does it do that? well, the ViewRootImpl asks the WindowManagerService for one Canvas to draw on. This means that all views in one window actually share a Canvas everytime there is a traversal.

As to your question, if only one specific View had a dirty rectangle then only that dirty rectangle would be drawn, but since another view had one as well then the dirty rectangle contains both.

这篇关于安卓:无效(脏)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆