如何在Android中的GLSurfaceview顶部添加透明背景的文本?
您好,我有一个具有背景的父视图组,包含一个 openglview 作为该视图组的一部分。
我想要的是,我需要一个具有透明背景的openglview,我希望能够看到父背景,并且我希望能够在openglview之上编写文本,我不想使用纹理。
我尝试了这个选项,
将 openglview zorderontop 设置为 true。它使我的文本位于 glview 后面。如果我没有将 zorderontop 设置为 true,则背景为黑色。
将半透明主题设置为使我的glview和父视图组变得透明的活动。
我尝试膨胀包含 glview 的布局并使用 ContexThemeWrapper 类动态更改 glview 的主题。但是 setTheme() 在运行时不起作用。仅在清单文件中应用主题才有效。
将布局背景应用于透明也不起作用,仍然是黑色背景。
Hi im having a parent viewgroup which has a background, contains a openglview as a part of that viewgroup.
What I want exactly is, i need a openglview with a transparent background and I want to able to see the parent background and I want to be able to write text on top of openglview, I dont want to use textures.
I tried this options,
Setting the openglview zorderontop as true. It makes my text to go behind the glview. If im not making zorderontop true, the background is black.
Setting the transluent theme to the activity which makes my glview and also the parent view group to become transparent.
I tried to inflate the layout contains the glview and use ContexThemeWrapper class to change the theme of the glview dynamically. But setTheme() not working at runtime. only applying theme in manifest file it works.
Applying the layout backgroud to transparent also didnt work, still black background.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您正在绘制两个单独的表面:一个由 ViewRoot 创建的表面,另一个为 GLSurfaceView 创建的表面。这些表面由 SurfaceFlinger 合成,一个在另一个之上。 (默认情况下,ViewRoot 表面将位于顶部,GLSurfaceView 表面将位于底部。)
由于所有视图都绘制到 ViewRoot 的表面中,因此它们必须全部位于 OpenGL 表面的顶部或 OpenGL 表面的下方。
如果您不想使用纹理,那么,您唯一的选择是创建第三个表面,这次使用 SurfaceView 而不是 GLSurfaceView,以在 GLSurfaceView 上方绘制文本。
The problem is that you're drawing to two separate surfaces: one surface created by ViewRoot, and one surface created for the GLSurfaceView. These surfaces are composited by SurfaceFlinger, one on top of the other. (By default the ViewRoot surface will be on top and the GLSurfaceView surface will be on bottom.)
Since all of your Views are drawn into the ViewRoot's surface, they must all be on top of the OpenGL surface or beneath the OpenGL surface.
If you don't want to use textures, period, your only choice is to create a third surface, this time with SurfaceView instead of GLSurfaceView, to draw your text above the GLSurfaceView.