Android: invalidate(dirty)

╄→尐↘猪︶ㄣ 提交于 2019-12-03 06:36:30

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.

Alireza Akhoundi

This problem is caused by hardware acceleration. You must disable it in your activity in order to use invalidate(dirty rect). To disable the hardware acceleration in your activity open the manifest file and add:

android:hardwareAccelerated="false"

Now you can use the invalidate(dirty rect).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!