两个SurfaceView显示预览的问题 setZOrderMediaOverlay(true)

工作中遇见过一个这样的需求:


启动后置相机,用一个SurfaceView (称其对象为SV1)显示预览,

拍照,然后关闭后置相机,

启动前置相机,用另一个SurfaceView(称其对象为SV2)显示前置预览


这个时候问题来了,前置预览显示不出来,startPreview也没有任何异常,

如果把SV1从layout中remove掉,SV2就可以正常显示前置预览。。。 。。。


如何才能不把SV1从layout中remove掉,也让SV2显示前置预览呢???


答案是只需要一个api,英语不好真心伤不起呀,开始没有看太懂。就没有太在意

public void setZOrderMediaOverlay (boolean isMediaOverlay)

Control whether the surface view's surface is placed on top of another regular surface view in the window (but still behind the window itself). This is typically used to place overlays on top of an underlying media surface view.

Note that this must be set before the surface view's containing window is attached to the window manager.


大致意思就是

setZOrderMediaOverlay
不论这个SurfaceView是否在其他SurfaceView的上面,这个api的作用通常就是将其覆盖在其他媒体上面

注意的大致意思就是 执行此api请确定在 layout.addView(thisSurface)之后。



所以,SV2.setZOrderMediaOverlay(true);

问题得解!!!




评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值