我試圖在首選項活動中顯示廣告,但從未出現。 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。這確實會顯示廣告,但它會被推到屏幕的右側,佔用的尺寸略小於一半(並切斷了廣告的一半)。