java - How to update a SurfaceView? -


i've extended surfaceview , managed draw in activity. activity should able call method on surfaceview changes parameter , redraws it. how can update function implemented?

this class:

public class mysurfaceview extends surfaceview                                     implements surfaceholder.callback {      private int circleradius = 50;     private surfaceholder sh;     private final paint paint = new paint(paint.anti_alias_flag);      public mysurfaceview(context context, attributeset as) {         super(context,as);         sh = getholder();         sh.addcallback(this);         paint.setcolor(color.blue);         paint.setstyle(style.fill);     }     public void surfacecreated(surfaceholder holder) {         canvas canvas = sh.lockcanvas();         canvas.drawcolor(color.black);         canvas.drawcircle(100, 200, circleradius, paint);         sh.unlockcanvasandpost(canvas);     }     public void update( newradius ) {         circleradius = newradius;         // more?     } } 

what should update contain redraw everything? have surfacechanged?

  • the update function should call invalidate() or postinvalidate() in order view redraw.
  • further, redrawing disabled default surfaceviews. enable calling setwillnotdraw(false) in e.g. surfacecreated.

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -