java - Why this code work only once [Android-canvas] -


i want draw circle in canvas. use function id:

      public static  void add()         {             float = 20 + (new random()).nextint(width-40);             float b = 20 + (new random()).nextint(height-40);               paint.setcolor(color.rgb(13, 13, 13));             c.drawcircle(a, b, r, paint);              paint.setcolor(color.rgb(119, 119, 119));             c.drawcircle(a, b, r-3, paint);         } 

it works once, when called "ondraw".

p.s. paint, width, height, c - public varibles.

upd.:

 protected void ondraw(canvas canv)     {         super.ondraw(canv);         c = canv;         paint = new paint();         paint.setstyle(paint.style.fill);         paint.setantialias(true);         paint.setcolor(color.white);         c.drawpaint(paint);         add();     } 

ondraw() called whenever view needs re-draw itself. can due many reasons, layout changing, scrolling etc.

you can call invalidate() on view cause re-draw.

if going draw @ high rate, touch painting or game etc, consider using textureview instead.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -