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 callinvalidate()
orpostinvalidate()
in order view redraw. - further, redrawing disabled default surfaceviews. enable calling
setwillnotdraw(false)
in e.g.surfacecreated
.
Comments
Post a Comment