我试图表现出偏好活动的广告,但它永远不会出现。 logcat中始终显示消息 “没有足够的空间来展示广告想:<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" />
所以布局被设置为宽度= 480dip高度= 75dip代替WRAP_CONTENT我可以改变它。 这确实显示了广告,但它是被推到了屏幕的右侧,占据了它的意思是略少于一半大小(并切断一半的广告)。