2012-11-21 87 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

相关问题