【问题标题】:How to add GLSurfaceView between Android Views?如何在 Android 视图之间添加 GLSurfaceView?
【发布时间】:2012-08-24 10:11:45
【问题描述】:

我正在开发 Android -Sandwich 类型的特殊 UI,即 GLSurfaceView 上的一个小型 GalleryView(带有透明区域),位于背景视图(LinearLayout+一些小部件)之上。这就是我正在考虑的设置方式:

<User>

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

在普通模式下,GLSurfaceView 在透明区域有黑色背景,所以我看不到底层,但是当我使用 setZOrderOnTop(true);我可以看到底层,但顶层(画廊)也位于 Glsurface 视图的后面。如何在架构中完成所需的视图?

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 布局方面需要帮助吗?
  • 我认为问题不在于布局,而在于 GLSurfaceView 设置。默认情况下,无论我做什么,它都不会显示透明区域,直到我没有 setZOrderOnTop(true);,但是这个设置将表面一直放在顶部......所以如何拥有相同的布局组成并在其中具有透明区域Glsurfaceview ?

标签: android android-layout glsurfaceview


【解决方案1】:

你不能这样做。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 2016-03-30
    • 2018-02-03
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    • 1970-01-01
    相关资源
    最近更新 更多