Canvas canvas = holder.lockCanvas();
canvas.drawRGB(255, 0, 0);
holder.unlockCanvasAndPost(canvas);
第一行,锁定Surface用于渲染并返回一个可用的Canvas
第二行,解锁Surface并确保通过Canvas进行绘制的内容可显示到屏幕上
例子:
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.view.Menu;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class MainActivity extends Activity {
FastRenderView renderView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
renderView = new FastRenderView(this);
setContentView(renderView);
}
protected void onResume() {//重载
super.onResume();
renderView.resume();
}
class FastRenderView extends SurfaceView implements Runnable
{
Thread r