AdMob无法在某些设备上完全显示

时间:2013-12-27 00:57:24

标签: android admob andengine ads 2d-games

我最近在AndEngine开发的Google Play“Meteor Dodge”上发布了一款应用,我在某些设备上展示广告时遇到了问题。看起来广告在开始时仅显示高度的5-10%,但在刷新间隔后,它看起来很完美。我无法解决这个问题,请帮忙。这是我的代码:

@Override
protected void onSetContentView() {
    // TODO Auto-generated method stub

    // CREATING the parent FrameLayout //
    final FrameLayout frameLayout = new FrameLayout(this);

    // CREATING the layout parameters, fill the screen //
    final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT);


    // CREATING a Smart Banner View //
    this.adView = new AdView(this);
    this.adView.setAdSize(com.google.android.gms.ads.AdSize.BANNER);
    this.adView.setAdUnitId("ca-app-pub-xxxxxxxxxx/xxxxxxxxxx");


    // Doing something I'm not 100% sure on, but guessing by the name //
    adView.refreshDrawableState();
    adView.setVisibility(AdView.VISIBLE);

 // Adview layout //
    final FrameLayout.LayoutParams adViewLayoutParams =
            new FrameLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    FrameLayout.LayoutParams.WRAP_CONTENT,
                                         Gravity.RIGHT|Gravity.TOP); 

    // REQUEST an ad 
    final AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest); 
    adView.bringToFront();

    // RENDER the add on top of the scene //
    this.mRenderSurfaceView = new RenderSurfaceView(this);
    mRenderSurfaceView.setRenderer(mEngine, this);

    // SURFACE layout ? //
    final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams =
            new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());

    // ADD the surface view and adView to the frame //
    frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
    frameLayout.addView(adView, adViewLayoutParams);

    // SHOW AD //
    this.setContentView(frameLayout, frameLayoutLayoutParams);


}

1 个答案:

答案 0 :(得分:0)

摆脱(他们没有必要)

adView.refreshDrawableState();
adView.setVisibility(AdView.VISIBLE);

adView.bringToFront();

替换

final FrameLayout.LayoutParams adViewLayoutParams =
        new FrameLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT,
                                     Gravity.RIGHT|Gravity.TOP); 

final FrameLayout.LayoutParams adViewLayoutParams =
        new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT,
                                     Gravity.RIGHT|Gravity.TOP); 

最重要的是不要打电话

adView.loadAd(adRequest);

直到之后您已将AdView添加到FrameLayout并且已设置ContentView。