tags:

views:

34

answers:

2

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.

A: 

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
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
A: 

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