Android SurfaceView清空画布

通过如下代码清空SurfaceView绘制

获取SurfaceHolder

view.holder.addCallback(object : SurfaceHolder.Callback {
	            override fun surfaceCreated(p0: SurfaceHolder) {
	                holder = p0
	                p0.setFormat(PixelFormat.TRANSPARENT);
            }

            override fun surfaceChanged(p0: SurfaceHolder, p1: Int, p2: Int, p3: Int) {
                holder = p0
                p0.setFormat(PixelFormat.TRANSPARENT);
            }

            override fun surfaceDestroyed(p0: SurfaceHolder) {
            }
        })

清空SurfaceHolder

        var canvas = holder?.lockCanvas()
        canvas?.let {
            it.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR)
        }
        holder?.unlockCanvasAndPost(canvas)

你可能感兴趣的:(android,SurfaceView)