WEB开发网
开发学院手机开发Android 开发 android中View类的开发框架 阅读

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 and

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:

1 2  下一页

Tags:android View 开发

编辑录入:coldstar [复制链接] [打 印]
赞助商链接