我正在为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) 我们一直在与SurfaceViews相关的一些问题进行斗争一个多星期,并找不到合适的解决方案.我们在论坛中阅读了有关类似问题的其他问题(甚至是Mixare源代码)但找不到答案,所以我们希望您能以某种方式帮助我们.
场景:我们有
问题:
无论我们如何努力,两个SurfaceViews显然都不能相处得很好.如果我们试图:
setContentView(mCameraPreview);
addContentView(mGLSurfaceView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
addContentView(mInfoView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
Run Code Online (Sandbox Code Playgroud)
(这似乎合乎逻辑),一切都按预期进行,直到我们锁定/解锁手机.之后,GLSurfaceView就会消失(不是InfoView,仍会显示).
相反,如果我们尝试:
setContentView(mGLSurfaceView);
addContentView(mCameraPreview, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
addContentView(mInfoView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
Run Code Online (Sandbox Code Playgroud)
然后问题是GLSurfaceView仅在锁定/解锁后出现,在此之前屏幕显示相机和InfoView.
我们发现,如果我们在显示视图的活动中执行onStart()之后将主线程休眠4.6秒(或更多),则行为与预期一致(即使在锁定/解锁后,也会显示相机,glsurface和info视图).
问题是,我们正在寻找更优雅的解决方案.
在我们看来,问题是相机花费的时间比预期的多Camera.open(),因此添加了相机视图,添加了GLSurfaceView,当相机实际打开时,它会在GLSurfaceView的顶部打开.关于这一点,我们bringToFront()在GLSurfaceView上使用了它,并将其放在信息视图的顶部,但是在锁定/解锁后,相机仍然在其上面打开,只留下一个带有摄像头预览的屏幕.
有任何想法吗?我们如何在它们之上显示SurfaceViews和信息视图?