2012-11-21 86 views
4

我是Android新手。 我加的AdMob在我的Android應用程序通過在main.xml中的以下變化:AdMob「沒有足夠空間顯示廣告」錯誤

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 
     <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" /> 

     <com.google.ads.AdView 
      xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
      android:id="@+id/adView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      ads:adSize="BANNER" 
      ads:adUnitId="XXXXXXXXX" 
      ads:loadAdOnCreate="true" /> 
    </LinearLayout> 
</TabHost> 

我的項目是成功的,沒有錯誤運行,但我沒有收到廣告。

WARN/Ads(3805): Not enough space to show ad! Wants: <320, 50>, Has: <320, 0>. 
+0

這個警告清楚地告訴你,顯示廣告沒有足夠的空間。它需要320x50的空間,其高度爲0.請檢查您的廣告查看是否有適當的空間。 – Scorpion

回答

6

這意味着在佈局中沒有空間顯示廣告。將其更改爲RelativeLayout並對齊父級底部。

<RelativeLayout 
      xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      > 
     <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:layout_below="@android:id/tabs"/> 

    <com.google.ads.AdView 
      xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
      android:id="@+id/adView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentBottom="true" 
      ads:adSize="BANNER" 
      ads:adUnitId="XXXXXXXXX" 
      ads:loadAdOnCreate="true" 
      /> 
</RelativeLayout> 
+0

thanksyou..but如何放置TabWidget? – Madhumitha

+0

我編輯了我的答案。嘗試一下。 –

+0

它的加載廣告在center.I嘗試layout_alignTop。但不工作。 – Madhumitha

0

這是造成這個問題。

<FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 

你的FrameLayout正處在view.So所有的高度,即使你寫下面的FrameLayout AdView中,它越來越0的高度。

在您的FrameLayout的運行時包含AdMob的Concider。

+0

的底部,並用RelativeLayout替換棄用的FrameLayout(此處不相關,但它從不傷害) – njzk2

相關問題