0

I have the following layout for my Android application, but the ads are not displayed. In the logcat, I have errors about "W/Adsīš• Not enough space to show ad. Needs 640x100, but only has 0x1038".

My layout :

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

    <ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    <android.support.v4.view.PagerTitleStrip
        android:id="@+id/pager_title_strip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="top" />
    </ViewPager>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="xxxxxxxx"/>
</LinearLayout>

How I load the ad in the Oncreate :

    adView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("xxxxxxx") //gnex
            .build();
    // Start loading the ad in the background.
    adView.loadAd(adRequest);

Any ideas ?

corenting
  • 3
  • 5

3 Answers3

0

Seems like there is now sufficient space to show you ad in linear layout. Do below things. 1) Either give some weight to adview. 2) Or change the linear layout to relative layout so that adview can have sufficent space to be displayed. 3) Also check whether you are getting ads in proper sizes.

Below link may also help you.

AdMob "Not enough space to show ad" error

Community
  • 1
  • 1
Vishal
  • 355
  • 3
  • 18
0

Change this one.

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

<ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">
<android.support.v4.view.PagerTitleStrip
    android:id="@+id/pager_title_strip"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top" />
</ViewPager>

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    ads:adSize="BANNER"
    ads:adUnitId="xxxxxxxx"/>
</LinearLayout>
Piyush
  • 18,895
  • 5
  • 32
  • 63
0

I suspect it is due to the layout_height config for pager.

android:layout_height="0dp"

Try changing it to

android:layout_height="wrap_content"
William
  • 20,150
  • 8
  • 49
  • 91