读书人

更新游戏画面时线程的有关问题

发布时间: 2012-09-29 10:30:01 作者: rapoo

更新游戏画面时线程的问题
作者daytodayme
http://www.iteye.com/topic/435147

调用Handler.post(Runnable r)方法,Runnable运行在UI所在线程,所以可以直接调用View.invalidate()


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(); } } } }

读书人网 >移动开发

热点推荐