Search code examples
javaandroidlayout

Make a SurfaceView transparent without setZOrderOnTop(true)


I have a RelativeLayout containing a custom SurfaceView and other elements that must be drawn over the SurfaceView. I also need the SurfaceView to be transparent. I tried this answer: how to make surfaceview transparent. But with the setZOrderOnTop(true) the other elements over the SurfaceView in the RelativeLayout are shown above the Surface (and partially hidden if the surface have something paint).

How can I solve this problem? thanks


Solution

  • Set the holder pixel format to RGBA_8888,

    sv.setZOrderOnTop(true);    //very much necessary
    

    getHolder().setFormat(PixelFormat.RGBA_8888);