每毫秒在一个canvas上画一些东西,是在canvas上添加一些细节,不是每次都重新画一遍。结果我的代码每次都返回了不同的画,这是怎么回事?
public void run() {
this.run = true;
Canvas canvas = null;
while (run) {
try {
canvas = this.surfaceHolder.lockCanvas();
synchronized (this.surfaceHolder) {
Thread.sleep(delay);
draw(new Img(canvas, size));
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if (canvas != null) {
this.surfaceHolder.unlockCanvasAndPost(canvas);
}
}
synchronized (this) {
if (wait) {
try {
wait();
} catch (Exception e) {}
}
}
}
}
可能是由于双缓冲机制,post上去后切换了个缓冲区