Android transparent canvas (surfaceview)

前端 未结 4 1435
萌比男神i
萌比男神i 2020-12-08 12:08

I\'ve got a panel which is placed on top of another view via a relativelayout.

I would like to give this panel a transparent background, but didn\'t find the correct

相关标签:
4条回答
  • 2020-12-08 12:53

    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);
    
    0 讨论(0)
  • 2020-12-08 12:56

    Try this:

    getHolder().setFormat(PixelFormat.TRANSLUCENT);
    
    0 讨论(0)
  • 2020-12-08 13:00

    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);
    
    0 讨论(0)
  • 2020-12-08 13:09

    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.

    0 讨论(0)
提交回复
热议问题