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

6

我正在开发一个特殊的Android用户界面 - 三明治类型,一个小的GalleryView在GLSurfaceView上(带有透明区域),位于背景视图(LinearLayout+一些小部件)之上。这是我考虑如何设置它:

<User>

顶部视图
---画廊视图
|
---GLSurfaceView(具有透明区域)
|
---LinearLayout(带小部件)
底部视图

在常规模式下,GLSurfaceView 在透明区域上有黑色背景,所以我看不到底层,但当我使用 setZOrderOnTop(true); 时,我可以看到底层,但顶层 (画廊) 也会被放在 GLSurfaceView 后面。如何实现像架构中所示的期望视图?

XML 代码示例(用 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>

我不太明白您需要我们做什么?您需要帮助编写XML布局吗? - Leonel Machava
2
我认为问题不在布局上,而是在GLSurfaceView的设置上。默认情况下,无论我做什么,它都不会显示透明区域,除非我没有设置setZOrderOnTop(true);但是这个设置会将表面放在最顶层...那么如何在Glsurfaceview中拥有相同的布局组合并具有透明区域呢? - prot0n
1个回答

3

你无法这样做。

GLSurfaceView的表面位于基于视图的UI的单独组合层上。它可以在视图之上或之下,但不能出现在视图元素之间。

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接