GLSurfaceView - how to make translucent background

后端 未结 5 1443
日久生厌
日久生厌 2021-01-04 19:08

I try to render using GLSurfaceView, and by docs I set format:

getHolder().setFormat(PixelFormat.TRANSLUCENT);

The I use GLSurfaceView.Rend

5条回答
  •  迷失自我
    2021-01-04 19:50

    Have you thought about using a LayerDrawable with setAlpha? Here's an example i have of two images... one is transparent (by the setAlpha) and the other is not. The 'calendar_cell' is solid and is on the back, then comes the box which is transparent to show the calendar cell behind it. This way you can stack as many images as you want giving them all a different transparency.

    Drawable []layers = new Drawable [2];
    int imageResource1 = mContext.getResources().getIdentifier("drawable/calendar_cell", null, mContext.getPackageName());
    Drawable background = v.getResources().getDrawable(imageResource1);
                            layers [0]= background;
    
    int imageResource = mContext.getResources().getIdentifier("drawable/box_" + box, null, mContext.getPackageName());
    Drawable boxImg = v.getResources().getDrawable(imageResource);
        boxImg.setAlpha(100);
        layers [1]= boxImg;
    
    LayerDrawable layerDrawable = new LayerDrawable (layers);
    v.setBackground(layerDrawable)
    

提交回复
热议问题