代码如下:
public class MySurface extends SurfaceView implements Callback ,Runnable{
Canvas can = null;
SurfaceHolder sfh;
Paint p;
private Thread th;
Context context;
public MySurface(Context context) {
super(context);
// TODO Auto-generated constructor stub
this.context = context;
this.getHolder().addCallback(this);
sfh = this.getHolder();
th = new Thread(this);
p = new Paint();
p.setAntiAlias(true);
p.setColor(Color.RED);
this.setKeepScreenOn(true);// 保持屏幕常亮
} public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub } public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub
th.start();
} public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub } public void run() { this.draw();
}
public void draw() {
System.out.println("draw is running");
can = this.getHolder().lockCanvas();
if(can == null){ System.out.println("can is null");
}
can.drawColor(Color.WHITE);// 刷屏
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);
can.drawBitmap(bitmap, 200, 200, p);
can.drawText("Himi", 100, 100, p);// 画文字文本
can.drawText("这就是简单的一个游戏框架", 100, 130, p);
}}在activity中new出来以后显示,结果也不报错,也不显示。怎么回事啊?
public class MySurface extends SurfaceView implements Callback ,Runnable{
Canvas can = null;
SurfaceHolder sfh;
Paint p;
private Thread th;
Context context;
public MySurface(Context context) {
super(context);
// TODO Auto-generated constructor stub
this.context = context;
this.getHolder().addCallback(this);
sfh = this.getHolder();
th = new Thread(this);
p = new Paint();
p.setAntiAlias(true);
p.setColor(Color.RED);
this.setKeepScreenOn(true);// 保持屏幕常亮
} public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub } public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub
th.start();
} public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub } public void run() { this.draw();
}
public void draw() {
System.out.println("draw is running");
can = this.getHolder().lockCanvas();
if(can == null){ System.out.println("can is null");
}
can.drawColor(Color.WHITE);// 刷屏
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);
can.drawBitmap(bitmap, 200, 200, p);
can.drawText("Himi", 100, 100, p);// 画文字文本
can.drawText("这就是简单的一个游戏框架", 100, 130, p);
}}在activity中new出来以后显示,结果也不报错,也不显示。怎么回事啊?
解决方案 »
- 给ImageButton设置translateanimation,在移动过程中无法获取焦点
- 真心求助、关于Notification图标问题
- 关于数据库创建路径
- Caused by: java.lang.ClassNotFoundException: net.sf.json.JSONObject in loader da
- android怎么设置桌面布局和快捷方式之类??
- android listVie的相关问题
- 关于动态加载fragment
- Android MediaPlayer引起的应用无响应(ANR)
- Android 打开应用
- Android 系统使用MediaCodec同时解码音视频问题
- 强烈抗议网通/电信 屏蔽 http://developer.android.com/sdk/index.html
- WCF service 如何通过TCP协议 与Android交互
th.start();