SurfaceView 顶部的按钮,在 Android 中将 setZOrderOnTop 设置为 true [英] Button on top of SurfaceView with setZOrderOnTop set to true in Android

查看:33
本文介绍了SurfaceView 顶部的按钮,在 Android 中将 setZOrderOnTop 设置为 true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个应用中有两个表面视图,一个表面视图需要与另一个表面视图重叠.例如,假设有两个表面视图 SurfaceView A 和 SurfaceView B.B 需要在 A 之上,这是通过在 B 上设置 setZOrderOnTop(true) 来实现的.

I have two surfaceviews in an app and one surfaceview needs to overlap the other surfaceview. For example, say there are two surfaceviews SurfaceView A and SurfaceView B. B needs to be on top of A which is accomplished by setting setZOrderOnTop(true) on B.

现在,我想在 B 的顶部显示一些文本或按钮,但因为它的 Z 顺序设置为 true,所以添加的文本或按钮不会显示在顶部,而是位于其下方.如果未设置 setZOrderOnTop 属性,则文本视图和按钮确实显示在顶部,但 B 不会与 A 重叠.

Now, I want to display some text or buttons on top of B but because it has Z order set as true the text or buttons added doesn't show on top but come underneath it. If the setZOrderOnTop property is not set then the text views and buttons does show up on top but then B doesn't overlap A.

我已经尝试将 SurfaceView B 和 textview 或按钮放在 FrameLayout 中,但它仍然出现在 B 下.有没有办法可以将 z order 设置为 true 并且仍然可以将文本或按钮放在上面?

I have tried placing SurfaceView B and the textview or buttons in FrameLayout but still it appears under B. Is there a way that z order can be set to true and still text or buttons can come on top of it?

推荐答案

我能够通过使用 setZOrderMediaOverlay(true) 而不是 setZOrderOnTop 来解决这个问题.

I was able to resolve the issue by using setZOrderMediaOverlay(true) instead of setZOrderOnTop.

方法 setZOrderOnTop 如果设置为 true 将始终位于窗口顶部.因此,为了在表面视图上叠加视图,应该使用 setZOrderMediaOverlay.

The method setZOrderOnTop if set to true will always be on top of the window. So, in order to have overlay view over surface view setZOrderMediaOverlay should be used.

有关详细信息,请参阅此处的 setZOrderMediaOverlay 文档.

这篇关于SurfaceView 顶部的按钮,在 Android 中将 setZOrderOnTop 设置为 true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆