2014-03-24 46 views
0

我敢肯定,问题是出在这里的某个地方:看不见的AdMob在cocos2dx

保护无效的onCreate(捆绑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已正确初始化。

+0

你需要问一个问题 – William

回答

0

我认为问题在于您计算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); 
+0

的getWidth和getHeight已过时,看到我的回答 – Narek

0

工作对我来说:

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