如何在同一个布局中使用多个 GLSurfaceView 组件? [英] How can I use Multiple GLSurfaceView components in the same Layout?

查看:32
本文介绍了如何在同一个布局中使用多个 GLSurfaceView 组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Android 编写信息可视化 API,但在尝试将自定义 GLSurfaceView 的两个单元放入布局时遇到了问题.此时的自定义GLSurfaceView只是GLSurfaceView的扩展,以消除自定义方法可能导致的故障.

I'm writing an Information Visualization API for Android and ran into a problem trying to place two units of a custom GLSurfaceView into a Layout. The Custom GLSurfaceView at this point is simply an extension of the GLSurfaceView to eliminate possible faults caused by custom methods.

当我在布局中添加了两个组件并启动它运行的应用程序时.但是什么也没画,好像进入了一个无限循环.因为渲染器中的调试消息会打印到 LogCat 中.但是,如果我只使用自定义 GLSurfaceView 组件之一,它就可以正常工作.

When I have both components added in layout and start the application it runs. But nothing is drawn, seems like it enters an infinite loop. because debug messages inside the Renderers are printed into the LogCat. However, It works perfectly fine if I only use one of the custom GLSurfaceView components.

我读到在多个活动中使用 GLSurfaceView 存在问题,我想它也适用于同时使用其中两个组件时.我已经尝试过发布 here 的解决方法,但似乎无法理解也可以工作.

I read that there is a problem using GLSurfaceView in multiple Activities and I suppose it also applies when using two of those components at the same time. I have tried the workaround posted here but cant seem to get it to work either.

如果有任何帮助,我将不胜感激.我选择使用 openGL 以获得更好的性能,但如果我不能一次使用多个组件,我想我将不得不使用 Canvas.

I would appreciate any help. I choose to use openGL for the better performance, but if I cant use multiple components at once I guess I'll have to use Canvas instead.

清单如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:text="@string/hello" android:id="@+id/TextView01"
        android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    <com.syntronic.vtadlib.VisualizationView android:id="@+id/glview"
        android:layout_width="fill_parent" android:layout_height="300px" />


    <TextView android:text="@string/hello" android:id="@+id/TextView02"
        android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    <LinearLayout 
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <com.syntronic.vtadlib.VisualizationView android:id="@+id/glview2"
            android:layout_width="fill_parent" android:layout_height="fill_parent" />

    </LinearLayout>

</LinearLayout>

从Activity看代码是这样的:

From the Activity the code is like this:

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    mSurfaceView = (VisualizationView) findViewById(R.id.glview);
    mSurfaceView2 = (VisualizationView) findViewById(R.id.glview2);

    //Enables debug flags for Errors
    //mSurfaceView.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR);   
    //mSurfaceView2.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR);  

    mSurfaceView.setRenderer(new CoordinateSystemRenderer());
    mSurfaceView2.setRenderer(new CoordinateSystemRenderer());

}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    mSurfaceView.onPause();
    mSurfaceView2.onPause();
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    mSurfaceView.onResume();
    mSurfaceView2.onResume();
}

我是否遗漏了一些明显的东西?或者有人可以解释为什么它不起作用?

Am I missing something obvious? Or can someone explain why it doesn't work?

推荐答案

[更新:这个答案不再正确,从 Android 5.0 (Lollipop) 开始.有关讨论和链接,请参阅 fadden 的答案.从 Android 2.0 开始也是不正确的,显然是甚至在此之前,只有重叠表面的问题.]

[UPDATE: This answer is no longer correct, as of Android 5.0 (Lollipop). See fadden's answer for a discussion, and links. It was also incorrect as of Android 2.0, and apparently was only an issue for OVERLAPPING surfaces even before then.]

您不能将 2 个 SurfaceViews(SV) 放入一个 Activity.了解为什么您应该了解 SV 的工作原理.

You cannot place 2 SurfaceViews(SV) into one Activity. For understand why you should know how SVs works.

当您创建它并将其放置在活动上时,它实际上不会被放置在活动中(或顶部),而是在当前活动的后面创建,并在该活动中创建透明"视图.

When you create it and place on activity it doesnt actually will be placed in activity (or top of it), instead it will be created behind of current activity with "transparent" view created in that activity.

在 Android 4.0 (API 14) 中有一个名为 TextureView没有办法在旧平台上创建类似的视图.

In Android 4.0 (API 14) there are new View called TextureView There are no way to create something like that View on older platforms.

这篇关于如何在同一个布局中使用多个 GLSurfaceView 组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆