android how to call invalidate(Rect)
I create class that extends LinerLayout and add many elements on view, also I add circle with etc canvas.drawCircle(100, 100, 10) a开发者_Go百科nd when I implement onTouchEvent I am not sure how to redraw only that element(circle). which parameters to set in "Rect" so I can send it to invalidate(Rect).
Thanks.
For the specific example, I think this code example does what you want. I moved your coordinates into variables (cx, cy, r) just to make it clear. Based on what you mentioned, I think you would call this from within your LinearLayout subclass.
int cx = 100;
int cy = 100;
int r = 10;
canvas.DrawCircle( cx, cy, r );
int l = cx - r - 1;
int t = cy - r - 1;
int r = cx + r + 1;
int b = cy + r + 1;
Rect bounds = new Rect(l, t, r, b);
invalidate(bounds);
I added an extra pixel on all sides just to overlap the circle a bit to ensure the entire area is invalidated. Based on my experience, it looks like you can include negative values or values that exceed the dimensions of the canvas.
精彩评论