SurfaceView本来就是采用双缓冲的技术实现的,所以此处只练习View的双缓冲使用
package com.Aina.Android;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
/**
* com.Aina.Android Pro_Canvas
*
* @author Aina.huang E-mail: 674023920@qq.com
* @version 创建时间:2010 Jun 17, 2010 3:14:33 PM 类说明
*/
public class GameView extends View {
private Bitmap mBitmap = null;
private Bitmap mBitmap2 = null;
private Canvas mCanvas = null;
private Paint mPaint = null;
public GameView(Context context) {
super(context);
mBitmap = ((BitmapDrawable) this.getResources().getDrawable(
R.drawable.img)).getBitmap();
mBitmap2 = Bitmap.createBitmap(320, 480, Config.ARGB_8888);//创建屏幕大小的缓冲区
mCanvas = new Canvas();
mCanvas.setBitmap(mBitmap2);//设置将内容绘制在mBitmap2上面
mPaint = new Paint();
mCanvas.drawBitmap(mBitmap, 0, 0, mPaint);//将图片绘制到缓冲屏幕上面
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(mBitmap2, 0, 0, mPaint);
}
}
package com.Aina.Android;
import android.app.Activity;
import android.os.Bundle;
public class Test_Canvas extends Activity {
/** Called when the activity is first created. */
private GameView gv = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gv = new GameView(this);
setContentView(gv);
}
}