两个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);

问题得解!!!




你可能感兴趣的:(android)