If I invalidate() a part of my custom view with a dirty rect parameter, how do I get the dirty rect inside the draw() method? The clipping rect of the canvas is not the same - in my experience, it's typically few times larger.
Asked
Active
Viewed 3,715 times
2 Answers
3
If the dirty rect is not the same as the one you passed to invalidate(), it is because another View or region of the screen was also invalidated.

Romain Guy
- 97,993
- 18
- 219
- 200
2
get the clipRect from the passed in Canvas object to onDraw method. This clipRect (Canvas::getClipBounds) is actually the invalidated Rect.
The clipRect is larger sometimes because different invalidated areas are unioned together so that one event is fired instead of firing multiple for performance reasons.

Faisal Feroz
- 12,458
- 4
- 40
- 51
-
In this particular case, there were no other invalidates. The test is very clean - the app sits tight for as long as I wish, then I tap the screen. This causes a redraw. There cannot possibly be another pending invalidation. – Seva Alekseyev Oct 06 '10 at 15:39
-
1I have the same experience here. getClipRect returns the boundary of the entire view instead of the small rect that I passed to invalidate. – Stephen Cheng Aug 25 '14 at 20:34
-
I don't think this answer is correct - my sample app sets a small rectangle but Canvas.getClipBounds() always returns the bounds for the whole view. – greg7gkb Mar 19 '16 at 03:13
-
According to this: https://stackoverflow.com/a/8947772/1942069 It seems using hardware accelerated views will set the clip bounds to the entire view. However, only the parts that intersect the clip rect will be drawn anyway. – Raslanove Sep 06 '18 at 02:26