2011-09-21 69 views
1

我已成功獲取AdMob測試廣告以顯示在LinearLayout中,但是如果我更改爲TableLayout,它們不會顯示出來。 logcat中沒有顯示錯誤。AdMob AdView不會顯示在TableLayout中

這是什麼在起作用:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    AdRequest request = new AdRequest(); 
    request.setTesting(true); 
    request.addTestDevice(AdRequest.TEST_EMULATOR); 
    AdView adview = new AdView(this, AdSize.BANNER, [admob id deleted for posting on stackoverflow]);   
    // all code before this point is the same in both examples 

    LinearLayout layout = new LinearLayout(this); 
    layout.addView(adview); 

    // all code after this point is the same in both examples 
    this.setContentView(layout); 
    adview.loadAd(request); 
} 

我得到了模擬器的屏幕,說的頂部一個可愛的小橫幅廣告「!成功現在,您可以通過App銀河[谷歌徽標]去旅行」 。到現在爲止還挺好。但它不會出現,如果我將它更改爲TableLayout,如下所示:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    AdRequest request = new AdRequest(); 
    request.setTesting(true); 
    request.addTestDevice(AdRequest.TEST_EMULATOR); 
    AdView adview = new AdView(this, AdSize.BANNER, [admob id deleted for posting on stackoverflow]);   
    // all code before this point is the same in both examples 

    TableLayout layout = new TableLayout(this); 
    TableRow row = new TableRow(this); 
    row.addView(adview); 
    layout.addView(row); 

    // all code after this point is the same in both examples 
    this.setContentView(layout); 
    adview.loadAd(request); 
} 

我在LogCat中沒有得到任何錯誤。在這兩種情況下(的LinearLayout或TableLayout)所有我來自AdMob logcat中得到的是二個信息的消息:

廣告獲得的廣告網址:<「URL」:「[URL到「應用銀河測試廣告]」>

廣告onRecievedAd()

就是這樣。沒有抱怨沒有足夠的空間,這在其他帖子中似乎很常見。我得到的只是一個黑屏。如果我以後添加了另一個TableRow,包含一個TextView,TextView在屏幕頂部下方顯示50px,就好像廣告在那裏一樣。

有關東西的任何想法,試圖讓它顯示出來?我已經寫了一個基於TableLayout的應用程序,如果可能的話,我寧願不必在LinearLayout中重做它。 。 。

+0

這是我要去用,除非別人來的東西了輝煌的:放在一個LinearLayout中的AdMob廣告,然後把TableLayout(應用程序,本質上)在同一個LinearLayout中。這是有效的,但是剝奪了我選擇將廣告放在我想要的位置 - 即,我寧願把它放在底部而不是頂部。 (如果我在TableLayout之後添加了AdView,LinearLayout由於某種原因給了TableLayout整個屏幕,並且AdView抱怨它沒有足夠的空間。)設計不佳,AdView佔用空間但沒有顯示任何內容,但沒有提供任何錯誤。 –

回答

0

我猜的AdView的家長應具備的使用性能:

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"