2011-07-04 67 views
2

我有我的AdMob代碼落實到我的XML文件是這樣的:Android的AdMob的-onReceivedAd擊中,但沒有廣告顯示

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5dp"> 

    <com.google.ads.AdView android:id="@+id/adView" 
        android:layout_width="30dp" 
        android:layout_height="30dp" 
        ads:adUnitId="???????" 
        ads:adSize="BANNER" 
        ads:loadAdOnCreate="false"/> 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp" /> 
</LinearLayout> 
</TabHost> 

在我的我的活動的onCreate方法:

// load ads 
    AdView adView = (AdView)findViewById(R.id.adView); 
    AdRequest request = new AdRequest(); 
    //request.setTesting(true); 

    adView.setAdListener(new AdListener() {  
     public void onReceiveAd(Ad arg0) { 
      // TODO Auto-generated method stub    
     }   
     public void onPresentScreen(Ad arg0) { 
      // TODO Auto-generated method stub 
     }   
     public void onLeaveApplication(Ad arg0) { 
      // TODO Auto-generated method stub 
     } 

     public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) { 
      // TODO Auto-generated method stub 
     } 

     public void onDismissScreen(Ad arg0) { 
      // TODO Auto-generated method stub 
     } 
    }); 

    adView.loadAd(request); 

我可以在onReceivedAd偵聽器中放置一個斷點,並且在運行我的應用程序時總是停在那裏;然而,沒有任何顯示。我的AdMob頁面也會顯示請求。我嘗試了進入和退出測試模式(參見上面的註釋行),結果相同。另外,爲避免任何人詢問,我的廣告:adUnitId =「????」設置爲在AdMob網站上我的應用旁邊找到的Publisher ID

任何人都有如何從這裏調試的建議?

+0

你爲什麼不把一些代碼(和它一個破發點)內的'公共無效onFailedToReceiveAd(廣告爲arg0,錯誤碼ARG1)'和看看是否有錯誤接收廣告? –

+0

@Aleks - 我在每個偵聽器方法中都有一行代碼(只是int i = 0; i ++)。唯一觸及的斷點是onReceivedAd - 其他3個總是跳過。 – bugfixr

+0

@mibollma - 你是對的人,我沒有注意到我把廣告放在了我的標籤主機中。我在頂部製作了一個LinearLayout,然後將adview和選項卡主機移到該主題中,並且它可以正常工作。通過一切手段,添加一個答案,以便您可以獲得信用:) – bugfixr

回答

1

刪除TabWidgetFrameLayout並再次嘗試僅用於測試。

我認爲android:layout_height="fill_parent"FrameLayout是問題所在。

0

佈局高度應爲50dp(或更多)才能展示廣告。廣告沒有獲得足夠的展示空間。檢查記錄器。

android:layout_height="50dp" 
了`AdListener`的

和寬度應WRAP_CONTENT