您的位置:首页 > 其它

surfaceview遮挡了上面的控件显示的解决方法

2016-12-21 20:11 781 查看
最近在项目中使用到surfaceview做视频的实时流,遇到一个很奇葩的效果 ,在使用surfaceview因为surfaceview是双缓存机制,所以他需要设置
setZOrderOnTop(true);

让他显示在所依赖的窗口的最顶层才能更好的显示


这个是在surfaceview里面找到的源码。

遇到这样的情况的解决办法是在surfaceview调用

setZOrderOnTop(true)之后调用 setZOrderMediaOverlay(true)就可以了覆盖在surfaceview就会显示出来了 ,点击事件也同样的响应。

/**
* 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.
*
* <p>Note that this must be set before the surface view's containing
* window is attached to the window manager.
*
* <p>Calling this overrides any previous call to {@link #setZOrderOnTop}.
*/
public void setZOrderMediaOverlay(boolean isMediaOverlay) {
mWindowType = isMediaOverlay
? WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY
: WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
}

这是setZOrderMediaOverlay(true)的源码。

看这两个源码,看他注释应该就很容易懂了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息