Android: How to get a custom view to redraw partially?
Posted
by Peterdk
on Stack Overflow
See other posts from Stack Overflow
or by Peterdk
Published on 2010-06-01T10:42:08Z
Indexed on
2010/06/01
10:43 UTC
Read the original article
Hit count: 469
I have a custom view that fills my entire screen. (A piano keyboard)
When a user touches the key, it would cause a invalidate()
to be called and the whole keyboard gets redrawn to show the new state with a touched key.
Currently the view is very simple, but I plan to add a bit more nice graphics. Since the whole keyboard is dynamically rendered this would make redrawing the entire keyboard more expensive.
So I thought, let's look into partial redrawing. Now I call invalidate(Rect dirty)
with the correct dirty region. I set my onDraw(Canvas canvas)
method to only draw the keys in the dirty region if I do indeed want a partial redraw. This results in those keys being drawn, but the rest of the keyboard is totally black/not drawn at all.
Am I wrong in expecting that calling invalidate(Rect dirty)
would "cache" the current canvas
, and only "allows" drawing in the dirty region?
Is there any way I can achieve what I want? (A way to "cache" the canvas and only redraw the dirty area?"
© Stack Overflow or respective owner