android - 如何在 Android 中将 UI 小部件放置在多个 Z 排序的表面 View 之上

标签 android android-layout surfaceview

我有 2 个 SurfaceViews 和 1 个 button 并且它们需要以类似于所附屏幕截图的方式排列。通过调用 surfaceViewB.setZOrderOnTop(true);

,我能够让 SurfaceView B 位于 SurfaceView A 之上

问题是,一旦我这样做,SurfaceView B 就会被放置在实际窗口之上,我无法再让 Button 位于它之上(例如调用 button.bringToFront() 在这里没用。

知道如何实现这种布局吗? enter image description here

最佳答案

您可以使用 setZOrderMediaOverlay(boolean) 将 SurfaceView B 放置在 SurfaceView A 之上,但仍在窗口后面。来自文档:Link :

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.

Calling this overrides any previous call to setZOrderOnTop(boolean).

因此,以下内容应该适合您:

surfaceViewB.setZOrderMediaOverlay(true);

关于android - 如何在 Android 中将 UI 小部件放置在多个 Z 排序的表面 View 之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19727087/

相关文章:

android - 删除后如何在android studio中制作AndroidTest?

android - 带有自定义 TextView 的 Tablayout,在首次启动时未更改选定状态颜色

Android:自定义 View 'PointsView':错误 "The following classes could not be instantiated"

android - 媒体播放器完成后如何清除表面支架?

java - 从相机、SurfaceView 或 SurfaceHolder 连续获取图像数据

android - 保存我的 recyclerview 和 cardview 的状态

android - HTML 站点图像背景在 iPhone 上显示错误

android - Android RxJava和Realm-RxJava错误处理是否可以捕获Realm发生的错误?

android - XML命名空间声明: auto-substitute package name

java - Android FrameLayout 中的分层 SurfaceView