1

我有一個android遊戲,繪製surfaceView和我有admob廣告的頂部,使用FrameLayout。 FrameLayout lay = new FrameLayout(this); this.addContentView(lay,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));谷歌播放服務的admob不顯示在表面視圖

AdView adView = new AdView(this, AdSize.BANNER, "xxxxxxxx"); 
    lay.addView(renderer, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
    lay.addView(adView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
    adView.setGravity(Gravity.LEFT); 
    this.setContentView(lay); 
    adView.loadAd(new AdRequest()); 

一切都很好。我想新的谷歌遊戲服務AdMob的整合,我已經改變了上面的代碼

FrameLayout lay = new FrameLayout(this); 
    this.addContentView(lay, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 

    adView = new AdView(this); 
    adView.setAdUnitId("xxxxxxx"); 
    adView.setAdSize(AdSize.BANNER); 
    lay.addView(adView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
    this.setContentView(lay); 
    AdRequest adRequest = new AdRequest.Builder().build(); 
    adView.loadAd(adRequest);   

的AdMob的觀點並沒有露面。我知道這是沒有出現的觀點,因爲如果我只將AdView添加到frameLayour,那麼我看到廣告沒有任何問題

有沒有人遇到過這個問題?有沒有人有任何建議?

王者問候

回答

0

確保您爲adview設置背景顏色。它可以是「透明的」。然後,使用RelativeLayout的或的FrameLayout作爲父佈局,定義佈局參數AD瀏覽被定位,例如在屏幕的這樣的底部中心:

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

     // Create an ad. 
     adView = new AdView(this); 
     adView.setAdSize(AdSize.BANNER); 
     adView.setAdUnitId(AD_UNIT_ID); 
     adView.setBackgroundColor(Color.TRANSPARENT); 
     // Add the AdView to the view hierarchy. The view will have no size 
     // until the ad is loaded. 
     RelativeLayout layout = new RelativeLayout(this); 
     layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 
     // Create an ad request. 
     AdRequest adRequest = new AdRequest.Builder().build(); 

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

     //Request full screen 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
     WindowManager.LayoutParams.FLAG_FULLSCREEN); 

     //Create a displayMetrics object to get pixel width and height 
     metrics = new DisplayMetrics(); 
     getWindowManager().getDefaultDisplay().getMetrics(metrics); 
     width = metrics.widthPixels; 
     height = metrics.heightPixels; 


    RelativeLayout.LayoutParams adParams = 
       new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
         RelativeLayout.LayoutParams.WRAP_CONTENT); 
      adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
      adParams.addRule(RelativeLayout.CENTER_HORIZONTAL); 

     layout.addView(renderer); 
     layout.addView(adView, adParams); 

     //Set main renderer    
     setContentView(layout); 

} 
+0

非常感謝當我設置一個顏色一切安好。我認爲它是一個「黑客」,但我不介意。 –

相關問題