【问题标题】:AdMob not displaying fully on some devicesAdMob 未在某些设备上完全显示
【发布时间】:2013-12-27 00:57:23
【问题描述】:

我最近在使用 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);


}

【问题讨论】:

    标签: android admob andengine ads 2d-games


    【解决方案1】:

    摆脱(它们不是必需的)

    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。

    【讨论】:

    • 我不知道为什么,但这只发生在某些设备上
    • 如果它只发生在某些设备上,那么您需要在您的问题中包含该信息。还要确保你做一个干净的构建。
    • 我正在做一个干净的构建,我确实将它包含在我的问题中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    • 2019-10-29
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    相关资源
    最近更新 更多