1

I was trying to add AdMob ads to my application. I'd like to add a banner right under a ListView, but no ads are shown and reading logs it looks like there's not enough space for the banner to show up.

08-17 20:11:00.976: E/Ads(7586): Not enough space to show ad! Wants: <320, 50>, Has: <992, 0>

Finally this is my whole layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/current_path_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/current_path"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/list_of_files"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </ListView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="XXXXXXXXXXXXX"
            ads:loadAdOnCreate="true"
            ads:testDevices="XXXXXXXXXXXXX" />
    </LinearLayout>

</LinearLayout>
Vektor88
  • 4,841
  • 11
  • 59
  • 111
  • 1
    unrelated, but why do you nest vertical `LinearLayout`s? Does not add any value but makes the App slower. – Henry Aug 17 '13 at 12:19
  • @Henry Following your advice it's working! I just removed nested LinearLayouts and I view it properly. – Vektor88 Aug 17 '13 at 12:24

2 Answers2

4

Just define weight on your listview....

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


        <TextView
            android:id="@+id/current_path_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Ding Chak"
            android:textAppearance="?android:attr/textAppearanceLarge" />


        <ListView
            android:id="@+id/list_of_files"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:layout_weight="1">
        </ListView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <com.google.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="XXXXXXXXXXXXX"
            ads:loadAdOnCreate="true"
            ads:testDevices="XXXXXXXXXXXXX" />
    </LinearLayout>

</LinearLayout>
Monica
  • 311
  • 1
  • 8
  • 22
FarhaSameer786
  • 370
  • 1
  • 4
  • 12
  • It's working, Henry's advice worked. Removing nested LinearLayouts made the trick. – Vektor88 Aug 17 '13 at 12:25
  • I removed the padding, I get this error with the same dp: W/Ads: Not enough space to show ad. Needs 411x49 dp, but only has 411x49 dp. https://stackoverflow.com/questions/48494316/exact-dimensions-of-not-enough-space-given-for-needs-has-dp-using-admob – quantumpotato Jan 29 '18 at 04:18
0

Simply set the margins to 0dp in res->values->dimens.xml

<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>
Gao
  • 3
  • 1
  • 3