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内容的实现
时间: 2024-10-24 04:08:35