我正在尝试向我的GlSurfaceView添加另一个视图但是我一直在犯错误。
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()。 “
显然我没有这样做,所以我如何才能获得glsurfaceview的额外视图?
由于
答案 0 :(得分:2)
其他人有这个问题......
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);