GLSurfaceView/SurfaceView 重叠
我之前问过这个问题,但没有收到回复,所以我再试一次。
我需要在 Motorola Xoom、Android 3.0 上制作带有一些随附标签和图形的渲染 2D 图片。虽然我需要的东西可以只用一个 SurfaceView (Canvas) 或一个 GLSurfaceView 来完成,但我真的很想同时使用两者,因为使用 GLSurfaceView 渲染速度更快,并且使用 SurfaceView 标记和图形更容易。视觉布局如下图所示。
我尝试通过在布局 XML 中的 GLSurfaceView 之后声明它来将 SurfaceView 放在顶部。 SurfaceView 是透明的(除了我明确绘制内容的地方),因此 GLSurfaceView 仍然可以看到。
这种方法效果很好,但有一个巨大的例外。我在 GLSurfaceView 区域中的 SurfaceView 上绘制的任何内容根本不会显示。为了验证这一点,我在边界上绘制了一些文本(一些在共享区域,一些仅在 SurfaceView 区域),并在 GLSurfaceView 边界处被截断。我尝试使用“bringToFront”方法来解决此问题,但没有成功。
谁能给我一些关于为什么这不起作用或者我能做些什么的想法?是GLSurfaceView在前面,还是GLSurfaceView直接写入显存,所以前面有东西也没关系?
I asked a question about this earlier but received no responses, so I'm trying again.
I need to do a rendered 2D picture with some accompanying labels and graphics on a Motorola Xoom, Android 3.0. Although what I need can be done with just a SurfaceView (Canvas) or just a GLSurfaceView, I would really like to use both because the rendering is faster with the GLSurfaceView, and the labeling and graphics are easier with the SurfaceView. The visual layout is as shown below.
I tried to put the SurfaceView on top by declaring it in the layout XML after the GLSurfaceView. The SurfaceView is transparent (except for where I explicitly draw stuff) so that the GLSurfaceView can still be seen.
This approach has worked pretty well with one huge exception. Anything that I draw on the SurfaceView that is in the GLSurfaceView region does not show up at all. To verify this I drew some text that was right on the boundary (some in the shared region, some just in the SurfaceView region), and it was chopped off at the GLSurfaceView boundary. I have tried using the "bringToFront" method to fix this, but it hasn't worked.
Can anyone give me some ideas on why this isn't working or what I can do about it? Is it that the GLSurfaceView is in front, or is that the GLSurfaceView writes directly to the video memory, so it doesn't matter if something is in front of it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SurfaceView 的工作方式将使其无法执行您想要的操作。您必须在 GLSurfaceView 内渲染文本。
The way SurfaceViews work will make it impossible to do what you want. You will have to render your text inside the GLSurfaceView.
切勿尝试将 GLSurfaceView 与任何东西(上方或下方)重叠。最好的情况是,它会在您的设备上损坏,并且您会尽早发现它;最坏的情况是,它可以在一台设备上运行,而不能在其他设备上运行。硬着头皮在 GL 视图中完成所有操作,或者什么也不做。如果您需要速度,那么 GL 就是您的最佳选择。
Never try to overlap a GLSurfaceView with anything (above or below). At best it breaks on your device and you catch it early, at worst it works on one device and not others. Bite the bullet and do everything in a GL view or none of it. If you need the speed then GL is the way to go.
我们应该将 setZOrderMediaOverlay 和 setZOrderOnTop 设置为 true 值
添加到 API 级别 5
void setZOrderMediaOverlay (布尔 isMediaOverlay)
控制表面视图的表面是否放置在窗口中另一个常规表面视图的顶部(但仍在窗口本身的后面)。这通常用于将覆盖层放置在底层媒体表面视图的顶部。
请注意,必须在将表面视图的包含窗口附加到窗口管理器之前设置此项。
调用此函数会覆盖之前对 setZOrderOnTop(boolean) 的任何调用。
添加到 API 级别 5
void setZOrderOnTop (布尔 onTop)
控制表面视图的表面是否放置在其窗口的顶部。通常它被放置在窗口后面,以允许它(在大多数情况下)看起来与层次结构中的视图合成。通过设置它,您可以将其放置在窗口上方。这意味着该 SurfaceView 所在窗口的任何内容在其表面上都将不可见。
请注意,必须在将表面视图的包含窗口附加到窗口管理器之前设置此项。
调用此方法会覆盖之前对 setZOrderMediaOverlay(boolean) 的任何调用。
请参考这个链接:
http://developer.android.com/reference/android/ view/SurfaceView.html#setZOrderMediaOverlay(boolean)
we should set setZOrderMediaOverlay and setZOrderOnTop to true value
Added in API level 5
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).
Added in API level 5
void setZOrderOnTop (boolean onTop)
Control whether the surface view's surface is placed on top of its window. Normally it is placed behind the window, to allow it to (for the most part) appear to composite with the views in the hierarchy. By setting this, you cause it to be placed above the window. This means that none of the contents of the window this SurfaceView is in will be visible on top of its surface.
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 setZOrderMediaOverlay(boolean).
Please refer to this link :
http://developer.android.com/reference/android/view/SurfaceView.html#setZOrderMediaOverlay(boolean)