【问题标题】:Admob via Adwhirl: Not enough space to show ad! Wants: 480, 75, Has: 480, 0来自 Adwhirl 的 Admob:没有足够的空间来展示广告!想要: 480, 75, 有: 480, 0
【发布时间】:2013-02-02 12:17:36
【问题描述】:

我已经四处搜索,似乎无法找到解决此问题的有效答案。

我得到的错误是“没有足够的空间来展示广告!想要:480, 75, Has: 480, 0”

由于某种原因,我的广告似乎没有可用高度。

这在 Haxe NME 上运行,我的手机是 HTC One S (540x960),搭载 Android 4.0.3

这是Java代码:

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();
        }
    });
}
}

【问题讨论】:

    标签: java android admob haxe adwhirl


    【解决方案1】:

    没有看到你的 XML 布局,我只能冒险猜测,但你会希望你的 XML 看起来像下面这样:

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

    您可能正在使用的布局是贪婪的,因此会占用所有可用空间。使用layout_above 将强制布局为广告留出空间。

    请记住,支持的第一条规则是 GIGO。错误或不完整的信息会导致错误的答案或根本没有答案,正如在第 198 个人甚至敢于猜测答案之前对您的问题的 197 次浏览所证明的那样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-04
      相关资源
      最近更新 更多