Admob广告未在我的应用中展示

时间:2013-07-29 14:20:41

标签: java android admob andengine

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);

}

1 个答案:

答案 0 :(得分: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设计。