android - GLSurfaceView 在其他视图之上
问题描述
我想GLSurfaceView
在我的活动上显示当前内容作为覆盖。但是下面的内容需要可见。
这是我的设置GLSurfaceView
:
setEGLConfigChooser(8, 8, 8, 8, 16, 0)
setZOrderOnTop(true)
holder.setFormat(PixelFormat.TRANSLUCENT)
setRenderer(renderer)
在渲染器中我有:
override fun onSurfaceCreated(unused: GL10, config: EGLConfig) {
// Set the background frame color
GLES20.glClearColor(1.0f, 0.0f, 0.0f, 0.1f)
}
override fun onDrawFrame(unused: GL10) {
// Redraw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT)
}
override fun onSurfaceChanged(unused: GL10, width: Int, height: Int) {
GLES20.glViewport(0, 0, width, height)
}
我可以看到它是半透明的,但透明度绝对不是 alpha 值的 10%。它要高得多。即使将清除颜色设置为 (1, 0, 0, 0),我也可以在主要内容之上看到非常饱和的红色叠加层。
任何想法如何在我的主要内容之上呈现 GLSurfaceView 并支持透明度?
解决方案
作为变体。您可以在单独的视图元素中显示 OpenGLES 渲染,并为其余活动内容设置透明度,例如:
<com.app.CustomSurfaceView
android:id="@+id/oglView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/button"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:text="Button"
android:textSize="38sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
结果:
推荐阅读
- ios - 在屏幕上放置视图 Swift
- spring - 为什么切换到具有显式@Imports 的单个@Configuration 类会破坏@WebMvcTest?
- angular - NGX-Bootstrap 导航栏下拉菜单不起作用
- android - Flutter - 在一次调用 setState() 后更新兄弟 Widget
- python - Python 和 RegEx:重复模式不起作用
- sql - 如何查询明天到期但出现“语法错误”的事情
- spring-boot - 在 docker 容器之间连接日志事件
- reactjs - 在 ReactJS 中四舍五入
- android - 现在是否可以根据风格更改应用插件或构建脚本依赖项?
- mysql - 触发器未在 MySQL 中触发