为了访问onDraw()之外的画布,我这样做:
private Canvas canvas;
public MyView(Context context, Paint paint) {
super(context);
canvas = new Canvas();
}
@Override
protected final void onDraw(Canvas canvas) {
canvas.save();
this.canvas = canvas;
}
然后我用它:
private class myScaleListener extends SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
canvas.setMatrix(matrix);
}
}
有一个更好的方法吗?
当我从canvas.setMatrix(matrix)
打电话给onDraw()
时,绘图正在转移。
提前致谢!!!
我想如果你改变一些东西,它看起来会更好:
private Canvas canvas;
public MyView(Context context, Paint paint) {
super(context);
canvas = null;
}
@Override
protected final void onDraw(Canvas canvas) {
this.canvas = canvas;
canvas.save();
}
private class myScaleListener extends SimpleOnScaleGestureListener {<br/>
@Override
public boolean onScale(ScaleGestureDetector detector) {
if(canvas != null) {
canvas.setMatrix(matrix);
}
}
}
看看它是否有效,我认为应该如此。