广告在preference活性QUOT;没有足够的空间来显示广告!想:其中,480,75>中有:其中,432,1073741823>" [英] Ad in preference activity "Not enough space to show ad! Wants: <480, 75>, Has: <432, 1073741823>"

查看:189
本文介绍了广告在preference活性QUOT;没有足够的空间来显示广告!想:其中,480,75>中有:其中,432,1073741823>"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示在preference活动的广告,但它永远不会出现。 LogCat中始终显示消息没有足够的空间来显示广告想:其中,480,75>,有:< 432,1073741823>

I'm trying to show an ad in the preference activity but it never appears. Logcat always shows the message "Not enough space to show ad! Wants: <480, 75>, Has: <432, 1073741823>"

这是我如何创建广告。我有一个自定义preference与广告

This is how I create the ad. I have a custom preference with the ad

public class AdmobPreference extends Preference {

public AdmobPreference(Context context, AttributeSet attrs, int defStyle) {super    (context, attrs, defStyle);}
public AdmobPreference(Context context, AttributeSet attrs) {super(context, attrs);}
public AdmobPreference(Context context) {super(context);}

@Override
protected View onCreateView(ViewGroup parent) {
    // this will create the linear layout defined in ads_layout.xml
    View view = super.onCreateView(parent);

    // the context is a PreferenceActivity
    Activity activity = (Activity)getContext();

    // Create the adView
    AdView adView = new AdView(activity, AdSize.BANNER, "MY KEY");

    ((LinearLayout)view).addView(adView);

    // Initiate a generic request to load it with an ad
    AdRequest request = new AdRequest();
    adView.loadAd(request);     

    return view;    
}
}

然后,我有一个布局的广告投入

Then I have a layout the ad is put into

<?xml version="1.0" encoding="utf-8"?>

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

</LinearLayout>

和它放入了preferences XML这一行:

And it is put into the the preferences xml with this line:

<com.my.package.name android:layout="@layout/admob_preference" />

我可以改变它,因此布局设置为宽度= 480dip高度= 75dip代替WRAP_CONTENT。这确实显示广告,但它被推到屏幕的右侧和占用它的意思(和切断一半广告)稍微小于一半的大小。

I can change it so the layout is set to width=480dip height=75dip instead of wrap_content. This does display the ad but it is pushed to the right of the screen and takes up a little less than half the size it's meant to (and cuts off half the ad).

推荐答案

看<一href="http://stackoverflow.com/questions/18274807/not-enough-space-to-show-ad-wants-480-75-has-432-1073741823?rq=1">similar问题

设置父的ViewGroup的填充为0解决了这个问题对我来说。

Setting the padding of the parent viewGroup to 0 solved this issue for me.

@Override
protected View onCreateView(ViewGroup parent) {
    //Next line solves the error by adjusting the padding of the parent ViewGroup
    parent.setPadding(0, 0, 0, 0);

    // this will create the linear layout defined in ads_layout.xml
    View view = super.onCreateView(parent);

    // the context is a PreferenceActivity
    Activity activity = (Activity)getContext();

    // Create the adView
    AdView adView = new AdView(activity, AdSize.BANNER, "MY KEY");

    ((LinearLayout)view).addView(adView);

    // Initiate a generic request to load it with an ad
    AdRequest request = new AdRequest();
    adView.loadAd(request);     

    return view;    
}

这篇关于广告在preference活性QUOT;没有足够的空间来显示广告!想:其中,480,75&gt;中有:其中,432,1073741823&GT;&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆