Admob广告在xml中显示错误

时间:2014-04-08 10:55:42

标签: android android-layout android-fragments admob

我陷入了问题并且搜索了很多,但无法找到解决方案,这是我的代码

    <com.google.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    app:adSize="BANNER"
    app:adUnitId="xxxxxxxxxx" >
</com.google.ads.AdView>

此代码显示

Error parsing XML:unbound prefix

当我删除app:adUnitId和app:adsize时,它不会出现任何错误,我该如何删除此错误?

2 个答案:

答案 0 :(得分:1)

您的错误是印刷的,您正在设置:

app:adSize="BANNER"
app:adUnitId="xxxxxxxxxx"

但它应该是:

ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxx"

答案 1 :(得分:0)

xmlns:ads="http://schemas.android.com/apk/res-auto"

将此添加到您的父标记。

就我而言。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background"
    android:orientation="vertical" >

希望这会奏效。