Android 帮助将另一个视图添加到GLSurfaceView

Android 帮助将另一个视图添加到GLSurfaceView,android,opengl-es,admob,Android,Opengl Es,Admob,我正在尝试将另一个视图添加到我的GLSURFACHEVIEW中,但是我不断地抛出错误 glView = new GLSurfaceView(this); glView.setRenderer(this); setContentView(glView); glView.setId(932203934); int newID = glView.getId(); // Create the adView

我正在尝试将另一个视图添加到我的GLSURFACHEVIEW中,但是我不断地抛出错误

 glView = new GLSurfaceView(this);
        glView.setRenderer(this);
        setContentView(glView);

        glView.setId(932203934);
        int newID = glView.getId();

            // Create the adView
        AdView adView = new AdView(this, AdSize.BANNER, "a14e3ef0948eb58");
        // Lookup your LinearLayout assuming it’s been given
        // the attribute android:id="@+id/mainLayout"
        //LinearLayout layout = (LinearLayout)findViewById(newID);
        GLSurfaceView layout = (GLSurfaceView)findViewById(newID);
        // Add the adView to it
        this.addContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        //layout.addView(adView);
        // Initiate a generic request to load it with an ad
        adView.loadAd(new AdRequest());
我添加了“setID”,因为glView总是给出-1,但是现在我得到了“java.lang.IllegalStateException:指定的子级已经有了父级。您必须首先对子级的父级调用removeView()

很明显,我做得不对,那么我如何对GLSURFACHEVIEW有这个额外的看法呢


谢谢

其他有此问题的人

AdView adView = new AdView(this, AdSize.BANNER, "a14e3ef0948eb58");
        LinearLayout ll = new LinearLayout(this);
        ll.addView(adView);
        this.addContentView(ll, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        AdRequest request = new AdRequest();
        request.setTesting(true);
        adView.loadAd(request);

GLSURFACHEVIEW不是ViewParent。您的根视图应该是相对的。给它一个id,这样你就可以找到它,然后对它调用addView()来添加adView。对不起,我现在没有使用任何xml,但我目前没有任何RelativeLayouts,为什么我现在需要创建一个?我添加了一个新的LinearLayout,并将其创建为xml,但在执行以下操作时返回null。。。LinearLayout布局=(LinearLayout)findViewById(R.id.LinearLayout);