解析 xml 时出错:来自 com.google.android.gms.ads.AdView 的未绑定前缀

zbz*_*vlv 5 java xml android admob

<com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="**************"
        ads:adSize="BANNER"
        ads:loadOnCreate="true"
        android:id="@+id/adView"/>
Run Code Online (Sandbox Code Playgroud)

我在这里有这个代码,带有 xmlns:ads,但仍然收到未绑定前缀的错误,并且需要 XML 属性“adsize”丢失。

Nik*_*esh 0

在您的情况下,添加了两个 xmlns:ads 名称空间。删除 xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads",它将起作用。

我也遇到了同样的问题,使用以下 xmlns,我可以解决该问题。

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

整个广告视图的代码如下。

    <com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@+id/textView1"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111"/>
Run Code Online (Sandbox Code Playgroud)