android - setting up drawable.invalidate to continuously draw on canvas -
i trying incrementally change alpha value of ovalshape().. need call invalidate , keeps calling , render increased alpha value..
but setup wrong, dont have idea this..
public class xml_anim_testing_sub_class extends view { private shapedrawable mdrawable; int x = 10; int y = 10; int width = 300; int height = 50; int my_alpha = 255,add_to_my_alpha = 0; public xml_anim_testing_sub_class(context context) { super(context); } protected void ondraw(canvas canvas) { x++; mdrawable = new shapedrawable(new ovalshape()); mdrawable.getpaint().setcolor(0xff74ac23); mdrawable.setalpha(my_alpha += add_to_my_alpha ); mdrawable.setbounds(x, y, x + width, y + height); if (my_alpha == 0) add_to_my_alpha = 1; if (my_alpha == 255) add_to_my_alpha = -1; mdrawable.draw(canvas); mdrawable.invalidateself(); } }
ok, found out solution, invalidate()
, difference between invalidate
, postinvalidate
? cos both working..
also, use of?
mdrawable.invalidateself()(cb);
instead of calling mdrawable.invalidateself()
, call postinvalidate()
(for view itself). schedule drawing pass after current 1 finishes.
also, don't need allocate new shapedrawable each time through ondraw. assign in constructor once. cut down on garbage generation.
Comments
Post a Comment