Look at the following code, it worked for me:
Paint clearPaint = new Paint(); public MySurfaceView(Context context, AttributeSet attrs) { super(context, attrs); this.setZOrderOnTop(true); this.getHolder().setFormat(PixelFormat.TRANSPARENT); clearPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); } public void drawMethod(){ Canvas canvas = this.getHolder().lockCanvas(); canvas.drawPaint(clearPaint); canvas.drawBitmap(yourBitmap, null, yourBitmapRect, null); this.getHolder().unlockCanvasAndPost(canvas); }
You need to put the SurfaceView on top in Z order and set the PixelFormat to transparent. This will make your SurfaceView transparent (this part that you did as you wrote). Then, before each new drawing, you should fill your surface with transparent paint. This "special" paint should be configured as follows:
clearPaint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
source share