Android Android Animation

I am trying to achieve surface animation. But my surface background is transparent, and I cannot clear the pixels of the last frame. Can I get some animations on a transparent surface? Perhaps I am only using the Animation class. Thanks!


Perhaps I did not describe the question clearly. I want to achieve animation, but the last chart cannot be updated on the surface. It looks like a picnic.

enter image description here

The background is transparent. I know that a canvas with a picture can clear the last drawn graph. But its background is transparent, the method does not reach the update. Please help me. Thank you

+4
source share
2 answers

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)); 
+8
source

you can try canvas.drawColor(Color.BLACK) at the beginning of every draw ()

+3
source

All Articles