小编Ruf*_*fio的帖子

如何在同一布局中使用多个GLSurfaceView组件?

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

当我在布局中添加了两个组件并启动它运行的应用程序时.但没有任何东西被绘制,似乎它进入了一个无限循环.因为Renderers中的调试消息被打印到LogCat中.但是,如果我只使用其中一个自定义GLSurfaceView组件,它的工作完全正常.

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

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

清单如下:

<?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>
Run Code Online (Sandbox Code Playgroud)

从Activity中,代码如下:

@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 …
Run Code Online (Sandbox Code Playgroud)

android opengl-es glsurfaceview android-layout

23
推荐指数
2
解决办法
9203
查看次数