android中View类的开发框架
2010-06-04 14:19:00 来源:WEB开发网android中View类的开发框架
package com.gamesurfaceview;
import android.R.integer;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
public class Activity01 extends Activity
{
private static final int REFRESH = 0x000001;
private GameSurfaceView mGameSurfaceView = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.mGameSurfaceView = new GameSurfaceView(this);
setContentView(mGameSurfaceView);
//start the thread
new Thread(new GameThread()).start();
}
Handler myHandler = new Handler()
{
public void handleMessage(Message msg)
{
switch (msg.what)
{
case Activity01.REFRESH:
mGameSurfaceView.invalidate();
break;
}
super.handleMessage(msg);
}
};
class GameThread implements Runnable
{
public void run()
{
while (!Thread.currentThread().isInterrupted())
{
Message message = new Message();
message.what = Activity01.REFRESH;
//send message
Activity01.this.myHandler.sendMessage(message);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO: handle exception
Thread.currentThread().interrupted();
}
}
}
}
public boolean onKeyUp(int keyCode, KeyEvent event)
{
switch (keyCode)
{
case KeyEvent.KEYCODE_DPAD_UP:
- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
- ››Android重启运用程序的代码
- ››Android为ListView的Item设置不同的布局
- ››android bitmap与base64字符串的互相转换
更多精彩
赞助商链接