4

I'm new to Android. I added AdMob in my android app by making the following changes in main.xml:

<?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>

My project is successfully running with no error, but I'm not getting the ad.

WARN/Ads(3805): Not enough space to show ad! Wants: <320, 50>, Has: <320, 0>.
Jim Blackler
  • 22,946
  • 12
  • 85
  • 101
Madhumitha
  • 3,794
  • 8
  • 30
  • 45
  • This warning clearly telling you that for showing the ad it does not have enough space. It requires 320x50 space and its height is 0. Please check that your adview get proper space. – Scorpion Nov 21 '12 at 10:52

2 Answers2

6

It means there is no space for to display ad in your layout. Change it to RelativeLayout and align parent bottom.

<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>
Kavin Varnan
  • 1,989
  • 18
  • 23
  • Its loading ad at the center.I tried layout_alignTop .but not working. – Madhumitha Nov 21 '12 at 11:12
  • There might be a problem with your TabHost. Cross check by setting a color to RelativeLayout android:background="@android:color/white", check if the ad is at the bottom of the layout – Kavin Varnan Nov 21 '12 at 11:16
0

This is causing the issue.

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

Your FrameLayout is occupying all the height on the view.So even if you write AdView below FrameLayout,It is getting 0 height.

Concider including AdMob at runtime inside your FrameLayout.

Vipul
  • 27,808
  • 7
  • 60
  • 75
  • and replacing the deprecated FrameLayout by a RelativeLayout (irrelevant here, but it never hurts) – njzk2 Nov 21 '12 at 11:10