与许多其他人一样,我尝试在相机预览(使用 SurfaceView)上绘制 3D 对象(使用 GLSurfaceView),以及放置在顶部的一些按钮。我实际上得到了一个可以工作的原型,但是我无法让 onResume 正常工作。恢复后,GLSurfaceView 留在后面并且不再可见。我知道它正在工作,因为如果我从布局中删除 SurfaceView,我可以很好地看到绘图。
目标是 Nexus One,运行原生 2.3.3 ROM。
这是布局 xml:
<com.example.cameratest.GLPreview
android:id="@+id/cubes"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<com.example.cameratest.Preview
android:id="@+id/camera"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/buttongroup"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right" android:gravity="center">
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:id="@+id/buttonClose"></Button>
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:id="@+id/buttonMode"></Button>
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:id="@+id/buttonCameraInfo"></Button>
</LinearLayout>
我已经为同样的问题苦苦挣扎了一段时间,但相信下面的代码现在可以工作了。 (暂停/锁定后,无论相机打开还是关闭,它都会继续工作)。
首先,我没有在布局文件中定义任何视图等 - 它们是在代码中创建的。以下是从主 onCreate() 方法调用的 - 请注意 augScreen 上的 setZOrderMediaOverlay()。
除了将 onPause() 和 onResume() 传递到 augScreen 之外,我在 onPause() 或 onResume() 中没有做任何特别的事情。
// 1 - Camera Preview
camScreen = new CameraPreview(this);
setContentView(camScreen, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// 2 - 3D object display
augScreen = new AR_SurfaceView(this, getViewRange());
addContentView(augScreen, new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
augScreen.setZOrderMediaOverlay(true);
// 3 - Permanent overlay
RelativeLayout overlayScreen = new OverlayView(this);
addContentView(overlayScreen, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
overlayScreen.setVisibility(View.VISIBLE);
// 4 - UI buttons (toggleable)
uiScreen = new UserInterfaceView(this);
addContentView(uiScreen, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)