設定アクティビティで広告を表示しようとしていますが、表示されません。Logcat は常に「広告を表示するための十分なスペースがありません! Wants: <480, 75>, Has: <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" />
レイアウトが wrap_content の代わりに width=480dip height=75dip に設定されるように変更できます。これにより広告は表示されますが、画面の右側に押し出され、本来のサイズの半分以下しか占有しません (そして、広告の半分が切り取られます)。