我怎样才能在相同的布局中使用多个GLSurfaceView组件?多个、组件、布局、GLSurfaceView

2023-09-06 13:11:25 作者:学会洒脱

我正在写为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 一个问题,我想用其中的两个组成部分,同时,当它也同样适用。我曾尝试解决方法贴这里但不能似乎得到它的工作无论是。

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.

我会AP preciate任何帮助。我选择使用OpenGL进行了更好的性能,但如果我不能一次我想使用多个组件我将不得不使用帆布代替。

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>

从活动的code是这样的:

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?

推荐答案

您不能将2 SurfaceViews(SV)为一体的活动。 对于理解为什么你应该知道的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.

在的Andr​​oid 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.