SurfaceView清空Canvas如何操作

public void ClearDraw(){

        Canvas canvas = null;
        try{

            canvas = surfaceHolder.lockCanvas(null);
            canvas.drawColor(Color.WHITE);
            canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.SRC);

        }catch(Exception e){


        }finally{

            if(canvas != null){

                surfaceHolder.unlockCanvasAndPost(canvas);

            }
        }
    }

在绘图之前调用这个方法就可以清除画布。

你可能感兴趣的:(Android)