自定义 SurfaceView 在 Android 中使透明

问题描述 投票:0回答:2

我通过扩展 calss SurfaceView 制作了自定义 MySurfaceView,它根据我的需要工作正常,但问题是黑色背景,我希望它透明。

我的代码是这样的。

lay = (LinearLayout)findViewById(R.id.timer_lay);

    MySurfaceView msv = new MySurfaceView(this);
    lay.addView(tv);

我希望

timer_lay
的背景颜色应该变成
MySurfaceView
的背景颜色,我可以在
onDraw
方法中做到这一点。

android surfaceview
2个回答
0
投票

是的,它对我有用得到了解决方案,感谢 g00dy

MySurfaceView msv = (MySurfaceView)findViewById(R.id.custom_view);
msv.setZOrderOnTop(true);   
sHolder = msv.getHolder();
sHolder.setFormat(PixelFormat.TRANSPARENT);

0
投票
MySurfaceView msv = new MySurfaceView(this);
msv.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
© www.soinside.com 2019 - 2024. All rights reserved.