您的位置:首页 > 产品设计 > UI/UE

利用Handler更新Android UI的另一种方法

2010-07-23 14:47 603 查看
其实文字游戏程序很简单,就是一个view和一个Activity,在利用下handier和postInvalidate()更新UI
我要实现的是一个蓝色正方形向右移出屏

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

myView = new MyView(this);
this.setContentView(this.myView);
new Thread(new myThread()).start();
}

class myThread implements Runnable {
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
myView.postInvalidate();
Thread.sleep(100);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: