Android Canvas总是画一个黑屏

时间:2014-12-02 16:05:09

标签: java android

我有一个问题画布总是画一个黑色的屏幕,无论我想画什么。 无论我什么时候想要内容视图是View类,或者我采取布局和 添加类或我让画布绘制背景等等

public class GameSurface extends SurfaceView {

private SurfaceHolder holder;

GameThread gameThread;
Bitmap background;

public GameSurface(Context context) {
    super(context);
    holder = getHolder();
    gameThread = new GameThread(this);
    background = BitmapFactory.decodeResource(getResources(), R.drawable.background1);


    holder.addCallback(new SurfaceHolder.Callback() {
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            gameThread.setRunning(true);
            gameThread.start();
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
            boolean retry = true;
            gameThread.setRunning(false);
            while (retry){
                try {
                        gameThread.join();
                    retry = false;

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }


        }
    });
}


@Override
protected void onDraw(Canvas canvas) {
    canvas.drawBitmap(background,0,0,new Paint());
}
}

重建和清洁不带任何东西!

问题是什么?

谢谢!

0 个答案:

没有答案