既存のアクティビティなしで AdView インスタンスを作成しようとしました:
https://developer.android.com/reference/com/google/android/gms/ads/AdView.html
AdView(Context context, AttributeSet attrs) // XML レイアウトから AdView を構築します。
XmlPullParser parser = context.getResources().getXml(R.xml.admob);
AttributeSet attributes = Xml.asAttributeSet(parser);
adView = new AdView(context, attributes);
さまざまな種類の XML コンテンツを試しましたが、適切な解決策が見つかりません。
私が試したXMLの一例:
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER">
</com.google.ads.AdView>
私が試しても、次の例外がスローされます。
LogCat: E/AndroidRuntime(29853): Caused by: com.google.ads.internal.b: Required XML attribute "adSize" missing
E/AndroidRuntime(29853): at com.google.ads.AdView.b(SourceFile:467)
E/AndroidRuntime(29853): at com.google.ads.AdView.a(SourceFile:336)
AdView コンストラクターのこのバリエーションを使用する方法の例を教えてもらえますか?