Kostadin Georgiev
Kostadin Georgiev

Reputation: 895

Not enough space for displaying AdMob banner(Android)

I have problem with displaying AdMob banners on small screens(In landscape mode is working). Tested on Galaxy S4, ads are shown, but on small screens only in landscape mode. I have tried changing xml layout parameters(width and height) to match_parent,wrap_content and fill_parent, but still same thing.

Error stack trace: 02-24 16:30:36.327: W/Ads(396): Not enough space to show ad. Needs 320x50 pixels, but only has 208x239 pixels.

My xml is:

<RelativeLayout 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:background="@raw/backgroundc"
    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" >

    <Button
        android:id="@+id/buttonGetLuck"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@layout/get_luck_custom_button"
        android:onClick="buttonGetLuck"
        android:text="Get Lucky"
        android:textStyle="italic"
        android:typeface="sans" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp"
        android:text="See your luck for today."
        android:textColor="#7CFC00"
        android:textSize="18sp"
        android:textStyle="italic"
        android:typeface="serif" />

    <LinearLayout
        android:id="@+id/bannerLayuout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>

My code is:

 // Create the adView.
    adView = new AdView(this);
    adView.setAdUnitId("*******");
    adView.setAdSize(AdSize.BANNER);

    // AdMob banner layout
    LinearLayout layout = (LinearLayout)findViewById(R.id.bannerLayuout);

    // Add the adView to it.
    layout.addView(adView);

    // Initiate a generic request.
    AdRequest adRequest = new AdRequest.Builder().build();

    // Load the adView with the ad request.
    adView.loadAd(adRequest);

Upvotes: 0

Views: 496

Answers (1)

Tony
Tony

Reputation: 11

I think that the problem could be "padding" on parent view.

try to remove these lines:

android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"

Upvotes: 1

Related Questions