Android transparent canvas (surfaceview)

限于喜欢 提交于 2019-11-28 06:06:08
Bilal Sammour

In the constructor:

setZOrderOnTop(true);

After holder.addCallback(this):

holder.setFormat(PixelFormat.TRANSPARENT);

At the beginning of drawing:

canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
ProjectJourneyman

I copied the solution from the same question: how to make surfaceview transparent and got it to work with a setup similar to yours.

The critical piece for me was the 'setZOrderOnTop(true)' setting, which I foolishly ignored on the first pass. I put that in the constructor, and set my pixel format to RGBA_8888 inside surfaceCreated.

At this point, the background from the top-level layout was visible.

Try this:

getHolder().setFormat(PixelFormat.TRANSLUCENT);
patrick

After searching with keyword surfaceview instead of canvas iI found out that it isn't possible. For more information see: how to make surfaceview transparent

Because the background of the canvas is static I've gave it the exact same background. Now it looks like it is transparent :)

    Bitmap bg = BitmapFactory.decodeResource(getResources(), R.drawable.background_panel_800_480);
    canvas.drawBitmap(bg, 0, 0, null);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!