SurfaceView背景透明:
setZOrderOnTop(true);
SurfaceHolder holder = this.getHolder(); holder.setFormat(PixelFormat.TRANSLUCENT);
清除Canvas内容的实现方式一:
Canvas canvas = null; try { synchronized (holder) { canvas = holder.lockCanvas(null); if (canvas == null) { return; } canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); } } catch (Exception e) { e.printStackTrace(); } finally { if (canvas != null) { holder.unlockCanvasAndPost(canvas); } }
方式二:
Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); canvas.drawPaint(paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
Android-清除Canvs内容的实现,布布扣,bubuko.com
原文:http://www.cnblogs.com/biyaxiong/p/3805645.html