Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在活动中使用GlSurfaceview_Android_Opengl Es_Android View_Glsurfaceview - Fatal编程技术网

Android 在活动中使用GlSurfaceview

Android 在活动中使用GlSurfaceview,android,opengl-es,android-view,glsurfaceview,Android,Opengl Es,Android View,Glsurfaceview,我有一个活动,我将活动的内容视图设置为“R.layout.main.xml”。我还有一个类,其中包含使用openGL创建的动画。现在我需要在活动的背景中使用此动画 代码是这样的 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_pixie); mGLView = new

我有一个活动,我将活动的内容视图设置为“R.layout.main.xml”。我还有一个类,其中包含使用openGL创建的动画。现在我需要在活动的背景中使用此动画

代码是这样的

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main_pixie);

    mGLView = new ClearGLSurfaceView(this);
    setContentView(mGLView);
 }

但是我的应用程序正在崩溃。我如何解决这个问题。

当你第二次调用
setContentView()
时,你会替换第一次设置的内容,只留下背景。崩溃很可能是因为您依赖于主布局中的元素,而主布局中的元素已被删除

与其调用两次
setContentView()
,不如在主布局中包含
GLSurfaceView
。下面是一个如何做到这一点的示例:

<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent>
    <your.application.package.ClearGLSurfaceView
         android:layout_width="match_parent"
         android:layout_width="match_parent"/>
    <!--put the rest of your layout here, i.e the contents of the original R.layout.main_pixie-->
</FrameLayout>
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main_pixie_new);
 }