我已经扩展了 SurfaceView 并在一个 Activity 中成功绘制它。这个 Activity 应该可以调用 SurfaceView 上的一个方法来改变一些参数并重新绘制它。如何实现更新函数呢?
这是我的类:
这是我的类:
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;
// What more?
}
}
< p > update
应该包含什么内容才能重新绘制所有内容?这与surfaceChanged
有关吗?