2015-11-02 66 views
0

這是我在MainActivity.java中的代碼。Libgdx遊戲中的Admob廣告不可見

有人可以幫助我解決這個問題:我使用eclipse,並在平板電腦上測試我的應用程序。它運作良好,但admob廣告不可見。

爲什麼?

RelativeLayout layout = new RelativeLayout(this); 
    RelativeLayout.LayoutParams gameViewParams = 
    new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
    RelativeLayout.LayoutParams.WRAP_CONTENT); 
    //gameViewParams.bottomMargin = 150; 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    View gameView = initializeForView(listener, cfg); 
    layout.addView(gameView, gameViewParams); 

    AdView adView = new AdView(this); 
    adView.setAdUnitId("Ad ID"); 
    //adView.setAdUnitId("app-id"); 
    adView.setAdSize(AdSize.BANNER); 

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

    layout.addView(adView, adParams); 

    AdRequest adRequest = new AdRequest.Builder().build(); 
    adView.loadAd(adRequest); 

    setContentView(layout); 

回答

0

與我的代碼相比,我看到的只有youradParams。

試試這個:

final RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
     adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
     adParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); 
+0

感謝它的工作原理,部份問題是,我沒有等待幾秒鐘,直到廣告將被展示。 – bolhaw

+0

感謝我的第一個代碼運行良好,問題是我沒有等待幾秒鐘,直到橫幅廣告將顯示。但現在我想添加橫幅廣告和intestitial廣告,你能幫助我嗎? – bolhaw

+0

這是我在Activity_main.java中的代碼,看下面的答案 – bolhaw