0

Admob 广告未显示在我的应用程序中。我感觉到广告正在加载,但由于我的布局安排,它没有显示。但我找不到它。这是我的代码

protected void onSetContentView() {       

    final RelativeLayout relativeLayout = new RelativeLayout(this);
    final FrameLayout.LayoutParams relativeLayoutLayoutParams = new FrameLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);

    this.mRenderSurfaceView = new RenderSurfaceView(this);
    mRenderSurfaceView.setRenderer(mEngine);

    final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.FILL_PARENT,
            FrameLayout.LayoutParams.FILL_PARENT,Gravity.CENTER);

    final android.widget.RelativeLayout.LayoutParams surfaceViewLayoutParams = new RelativeLayout.LayoutParams(layoutParams);
    surfaceViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    relativeLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);


    FrameLayout frameLayout = new FrameLayout(this);        
    adView = new AdView(this, AdSize.BANNER, "##############");
    adView.refreshDrawableState();
    adView.setVisibility(AdView.VISIBLE);
    frameLayout.addView(adView);
    relativeLayout.addView(frameLayout);
    this.setContentView(relativeLayout, relativeLayoutLayoutParams);

}
4

1 回答 1

1

您已将 SurfaceView 告知 FILL_PARENT,因此它占用了所有空间,没有为 AdView 兄弟姐妹留下任何空间。

final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.FILL_PARENT,
            FrameLayout.LayoutParams.FILL_PARENT,Gravity.CENTER);

另请注意,不需要 FrameLayout 包装 AdView。

我建议您遵循 jquery404 的建议并在 XML 中定义布局。你会更好地理解你的 ui 设计。

于 2013-07-29T22:01:03.450 回答