如何在Android视图之间添加GLSurfaceView?

pro*_*t0n 6 android glsurfaceview android-layout

我正在使用Android -Sandwich类型的特殊UI,GLSurfaceView上的一个小GalleryView(带有透明区域)在背景View(LinearLayout +一些小部件)之上.这就是我想要设置它的方式:

<User>
Run Code Online (Sandbox Code Playgroud)

TOP View
--- GalleryView
|
--- GLSurfaceView(带透明区域)
|
--- LinearLayout(带小部件)
BOTTOM View

在常规模式下,GLSurfaceView在透明区域上有黑色背景,所以我看不到底层,但是当我使用setZOrderOnTop(true)时; 我可以看到底层,但顶层(图库)也落后于Glsurface视图.如何在模式中完成所需的视图?

XML code dummy示例(使用AnalogClock而不是GalleryView):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#920000"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right" >

        <AnalogClock
            android:id="@+id/analogClock2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <com.test.CustomGlView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gl_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <AnalogClock
        android:id="@+id/Gallery_dummyview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

fad*_*den 3

你不能这样做。

GLSurfaceView 的 Surface 位于与基于视图的 UI 不同的组合层上。它可以位于视图之上或之下,但不能夹在视图元素之间。

您可以改用TextureView (API 14+)。它有一个要渲染的 Surface,但由应用程序合成到视图层上,因此布局的工作方式就像任何其他视图一样。您需要为 GLES 提供自己的 EGL 设置和线程管理,而不是依赖 GLSurfaceView 中的内容,但您可以在Grafika中找到示例。