【问题标题】:Can't see admob in cocos2dxcocos2dx中看不到admob
【发布时间】:2014-05-02 05:14:00
【问题描述】:

我很确定问题出在某个地方:

protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);

      // Create an ad.
    adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId(AD_UNIT_ID);

    // Add the AdView to the view hierarchy. The view will have no size
    // until the ad is loaded.
    LayoutParams adParams = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);


    // Create an ad request. Check logcat output for the hashed device ID to
    // get test ads on a physical device.
    AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
        .build();

    // Start loading the ad in the background.
    adView.loadAd(adRequest);
    addContentView(adView, adParams);
}

是的,id 已正确初始化。

【问题讨论】:

  • 你需要问一个问题

标签: android admob


【解决方案1】:

我认为问题在于您在 adParams 中计算位置的方式。这是我使用的代码,它将广告放在屏幕底部:

LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
            getWindowManager().getDefaultDisplay().getWidth(),                        
            getWindowManager().getDefaultDisplay().getHeight()+getWindowManager().getDefaultDisplay().getHeight()-110);

adView = new AdView(this, AdSize.BANNER, “XXXXXX”);

AdRequest request = new AdRequest();
adView.loadAd(request);                
addContentView(adView, adParams); 

【讨论】:

  • getWidth 和 getHeight 已弃用,请参阅我的回答
【解决方案2】:

为我工作:

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int screenWidth = displaymetrics.widthPixels;
int screenHeight = displaymetrics.heightPixels;


LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(screenWidth, screenHeight + screenHeight-70);

 // Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);

// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
    .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
    .build();

// Start loading the ad in the background.
adView.loadAd(adRequest);


// Adding full screen container
addContentView(adView, adParams);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多