2

I have searched around and cannot seem to find an answer to an answer to this issue that works.

The error I get is "Not enough space to show ad! Wants: 480, 75, Has: 480, 0"

It seems that for some reason my ad has no height available.

This runs on Haxe NME and my phone is an HTC One S (540x960) with Android 4.0.3

Here is the Java code:

public class AdWhirl
{
public static RelativeLayout adLayout;
public static GameActivity activity;
public static String code;

public static void init(String code)
{
    AdWhirl.code = code;
    activity = GameActivity.getInstance();

    activity.runOnUiThread(new Runnable() 
    {
        public void run() 
        {
            adLayout = new RelativeLayout(activity);

            //Nothing works till this is set.
            AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);

            RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
            ViewGroup view = (ViewGroup) activity.getWindow().getDecorView();
            ViewGroup content = (ViewGroup) view.getChildAt(0);
            content.addView(adLayout, p);
        }
    });
}

public static void showAd(final int position)
{
    if(activity == null)
    {
        return;
    }

    activity.runOnUiThread(new Runnable() 
    {
        public void run() 
        {
            AdWhirlLayout l = new AdWhirlLayout(activity, code);
            l.setMaxHeight(75); //AdMob asks for this minimum height

            RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 

            //Bottom-Center
            if(position == 0)
            {
                p.addRule(RelativeLayout.CENTER_HORIZONTAL);
                p.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            }

            //Top-Center
            else
            {
                p.addRule(RelativeLayout.CENTER_HORIZONTAL);
                p.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            }

            adLayout.addView(l, p);
        }
    });
}

public static void hideAd()
{
    if(activity == null)
    {
        return;
    }

    activity.runOnUiThread(new Runnable() 
    {
        public void run() 
        {
            adLayout.removeAllViews();
        }
    });
}
}

1 Answers1

0

Without seeing your XML layout, I can only hazard a guess, but you're going to want your XML to look something like the following:

<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:id="@+id/main_relative_layout_ad"
    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=".GameActivity" >

    <!-- Note the layout_above attribute, below --> 

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:layout_above="@+id/adView"
        android:gravity="center"
        android:text="@string/your_text_here" />

    <!-- Note the alignParentBottom attribute, below --> 

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

</RelativeLayout>

The layout you're probably using is greedy and is therefore sucking up all available space. Using layout_above will force the layout to leave space for the advert.

Please remember that the first rule of support is GIGO. Bad or incomplete information results in either a bad answer or no answer at all, as demonstrated by the 197 views on your question before the 198th person even dared to guess at an answer.

MarsAtomic
  • 10,436
  • 5
  • 35
  • 56