Android: Invalidate(dirty)
Solution 1:
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.
Solution 2:
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)
.
Post a Comment for "Android: Invalidate(dirty)"