package my.test1;import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;public class test1Activity extends Activity {
/** Called when the activity is first created. */
private GameView mGameView=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new Thread(new GameThread()).start();
System.out.println("Activity.Oncreate");
}
class GameThread implements Runnable{ @Override
public void run() {
// TODO Auto-generated method stub
System.out.println("Thread.run");
while (!Thread.currentThread().isInterrupted()){
try{
Thread.sleep(100);
}
catch(InterruptedException e){
Thread.currentThread().interrupt();
}
System.out.println("postInvalidate 上方");
mGameView.postInvalidate(); }
}
}
public class GameView extends View{ public GameView(Context context) {
super(context);
// TODO Auto-generated constructor stub
} private Paint mPaint = null;
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
System.out.println("onDraw");
mPaint = new Paint();
canvas.drawColor(Color.BLUE);
mPaint.setColor(Color.BLACK);
canvas.drawCircle(40, 70, 30, mPaint);
}
}
}
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;public class test1Activity extends Activity {
/** Called when the activity is first created. */
private GameView mGameView=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new Thread(new GameThread()).start();
System.out.println("Activity.Oncreate");
}
class GameThread implements Runnable{ @Override
public void run() {
// TODO Auto-generated method stub
System.out.println("Thread.run");
while (!Thread.currentThread().isInterrupted()){
try{
Thread.sleep(100);
}
catch(InterruptedException e){
Thread.currentThread().interrupt();
}
System.out.println("postInvalidate 上方");
mGameView.postInvalidate(); }
}
}
public class GameView extends View{ public GameView(Context context) {
super(context);
// TODO Auto-generated constructor stub
} private Paint mPaint = null;
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
System.out.println("onDraw");
mPaint = new Paint();
canvas.drawColor(Color.BLUE);
mPaint.setColor(Color.BLACK);
canvas.drawCircle(40, 70, 30, mPaint);
}
}
}
解决方案 »
- html如何关闭安卓浏览器??
- 新年财记,源码分享
- Android APP中如何打开浏览器 并以POST方式传递参数
- 求指教:listview点击无反应。
- android怎么往xml文件里添加节点,速度啊。。。非常急需!!!!!!
- 请问安装android sdk manager,下载速度为什么这么慢?
- 这是怎么回事呢?运行不起来。。。求助~~~
- 去掉Activity标题栏,影响了AlertDialog样式。
- 双精度怎么强制转字符串型
- Android studio configure build 一直报错Cause: unable to find valid certification pat
- pin码,输入3次之后,没有输入PUK码框界面
- emulator下sd card的更改
这句你应该设置你的GameView
谢谢您,我试过了,是可以的。可还是有异常。我还想问一下,如果我既要绘图,还要引用 XML 中的布局设置该怎么做。
引用时需要加上package名,例如<my.test1.GameView ...></my.test1.GameView>