解决SurfaceView调用setZOrderOnTop(true)遮挡其他控件的问题

来源:互联网 发布:酷站棋牌源码论坛 编辑:程序博客网 时间:2024/05/16 18:30
1、SurfaceView遮挡其他控件的项目背景:
由于要实现视频、地图大小窗口切换功能,所以在布局里同时使用了MapView和SurfaceView,textview、imageview、自定义控件各种按钮控件。在这种背景下,问题出现了,如果用相关开发基础的同学应该知道,当MapView和SurfaceView同时在一个布局里面,如果想让SurfaveView显示图片或者视频必须要调用SurfaceView.setZOrderOnTop(true),也就是说必须把SurfaceView置于Activity显示窗口的最顶层才能正常显示,然后调用了SurfaceView.setZOrderOnTop(true)又导致了其他控件比如播放、快进等按钮被遮挡。网上有很多解决方案,比如解决SurfaceView设置透明造成遮盖其他组件的替代方案,对于视频播放的页面都不够完美,因为它是直接在SurfaceView上面绘制相关的控件,试想一下如果在SurfaceView的某些区域绘制了一些按钮,势必会挡住一部分视频画面,这样对于用户来说是很难接受的。


2、从SurfaceView源码中寻找解决方案:
由于在网上找的解决方案都不能满足要求,没办法有折回来查看了下SurfaceView的源码,在查看源码的时候看到这个方法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.
  Calling this overrides any previous call to {@link #setZOrderOnTop}.
  大概的意思就是说控制窗口中表面的视图层是否放置在常规视图层的顶部。
  最终,我在调用setZOrderOnTop(true)之后调用了setZOrderMediaOverlay(true),OK,遮挡问题完美解决!
阅读全文
0 0
原创粉丝点击