我尝试使用下面的代码显示添加内容。 我收到错误“ AdView缺少需要的xml属性adSize ”。
有什么问题?
main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res/com.jms.AdmobExample"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="a14f1d807e488dd" />
</LinearLayout>
attr.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="com.google.ads.AdView">
<attr name="adSize">
<enum name="BANNER" value="1"/>
<enum name="IAB_MRECT" value="2"/>
<enum name="IAB_BANNER" value="3"/>
<enum name="IAB_LEADERBOARD" value="4"/>
</attr>
<attr name="adUnitId" format="string"/>
</declare-styleable>
</resources>
答案 0 :(得分:3)
使用此
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res/com.jms.AdmobExample"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res/com.jms.AdmobExample"
android:id="@+id/add_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ns:adSize="BANNER"
ns:adUnitId="a14f1d807e488dd" >
</com.google.ads.AdView>
</Linearlayout>
答案 1 :(得分:2)
要使其适用于Google Play服务,请使用:
的xmlns:广告= “http://schemas.android.com/apk/res-auto”
在您的XML文件中。
答案 2 :(得分:0)
您的adsize属性似乎无法识别。
我想说,要么你的命名空间属性是问题(添加它),你应该检查你是否调用attr.xml“attrs.xml”,因为它应该是。
请注意,this说新版本的AdMob不需要attrs.xml。
答案 3 :(得分:0)
你在xml文件中缺少这个:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"