我试图在首选项活动中显示广告,但从未出现。 Logcat总是显示消息“没有足够的空间显示广告!想要:< 480,75>,具有:< 432,1073741823>”广告优先活动”没有足够的空间来显示广告!想要:<480, 75>,已:<432,1073741823>“
这是我如何制作广告。我有与广告
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;
}
}
然后,我有一个布局的广告投入
<?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>
它放入喜好XML这一行定制的偏好:
<com.my.package.name android:layout="@layout/admob_preference" />
我可以改变它,所以布局设置为width = 480dip height = 75dip而不是wrap_content。这确实会显示广告,但它会被推到屏幕的右侧,占用的尺寸略小于一半(并切断了广告的一半)。