public class myView extends View implements Runnable{ public myView(Context context) {
super(context);
new Thread(this).start();
} @Override
protected void onDraw(Canvas canvas) {
。//绘制
super.onDraw(canvas);
} public void run() {
while(true){
try {
update(); //逻辑
postInvalidate(); //重绘
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}}run方法中调用postInvalidate(),有时候run 和 onDraw是不同步的,我想让本次onDraw 都绘制完成,然后再执行run的下次循环,急求解决办法~~~~~~~~~~~~~~~~~~~~~~~~
protected void onDraw(Canvas canvas) {
synchronize(this)
{
。//绘制
}
super.onDraw(canvas);
}
就用一个 boolean 变量,在 onDraw 中设置为 true, 把你那个如果为变量为 true,在开进程,在run中把这个变量设置为 false