我正在为 Android 编写信息可视化 API,但在尝试将自定义 GLSurfaceView
的两个单元放入布局时遇到了问题。此时的自定义GLSurfaceView
只是GLSurfaceView
的扩展,以消除自定义方法可能导致的故障。
当我在布局中添加了两个组件并启动它运行的应用程序时。但是什么也没画,好像进入了一个无限循环。因为渲染器中的调试消息会打印到 LogCat 中。但是,如果我只使用自定义 GLSurfaceView
组件之一,它就可以正常工作。
我读到在多个 Activity 中使用 GLSurfaceView
存在问题,我想它也适用于同时使用其中两个组件时。我已尝试发布 here 的解决方法但似乎也无法让它工作。
如果有任何帮助,我将不胜感激。我选择使用 openGL 以获得更好的性能,但如果我不能一次使用多个组件,我想我将不得不使用 Canvas。
list 如下所示:
<?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看代码是这样的:
@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();
}
我是否遗漏了一些明显的东西?或者有人可以解释为什么它不起作用?
最佳答案
[更新:从 Android 5.0 (Lollipop) 开始,此答案不再正确。见 fadden's answer讨论和链接。 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 的工作原理。
当您创建它并将其放置在 Activity 上时,它实际上不会被放置在 Activity 中(或 Activity 顶部),而是会在当前 Activity 的后面创建,并在该 Activity 中创建“透明” View 。
在 Android 4.0 (API 14) 中,有一个名为 TextureView 的新 View 没有办法在旧平台上创建类似的 View 。
关于android - 如何在同一个布局中使用多个 GLSurfaceView 组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4991095/