首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

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

2012-09-29 
更新游戏画面时线程的问题作者daytodaymehttp://www.iteye.com/topic/435147调用Handler.post(Runnable r)

更新游戏画面时线程的问题
作者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(); } } } }

热点排行