com.admob.android.ads.AdView未绑定前缀?

问题描述 投票:27回答:6

我试图将admob包含在Eclipse中的Android应用程序中。但是我在layout.xml中遇到错误。 Eclipse告诉我com.admot.android.ads.AdView是一个未绑定的前缀。我按照pdf指令在构建路径中包含了admob库。但它似乎仍然没有找到AdView类。但为什么?

这是产生错误的布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    >

            <renegrothmann.kalah.GameView
                android:id="@+id/gameView" android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_margin="2px"
                />

            <com.admob.android.ads.AdView
                android:id="@+id/ad"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                myapp:backgroundColor="#000000"
                myapp:primaryTextColor="#FFFFFF"
                myapp:secondaryTextColor="#CCCCCC"
                />

</LinearLayout>
android admob
6个回答
91
投票

这个布局我有同样的错误

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/topLayout"
>           
    <!-- Ad Placeholder -->
    <com.google.ads.AdView      
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="a14df07c16f171a"
        ads:adSize="BANNER"
        ads:loadAdOnCreate="true"
    />

</RelativeLayout>

然后我做到了:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/topLayout"
>           
    <!-- Ad Placeholder -->
    <com.google.ads.AdView      
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="a14df07c16f171a"
        ads:adSize="BANNER"
        ads:loadAdOnCreate="true"
    />

</RelativeLayout>

注意第二个例子中我的RelativeLayout中的第二个xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"? 事实上,如果你删除android命名空间声明xmlns:android="http://schemas.android.com/apk/res/android"它将开始抱怨所有的Android组件。


5
投票

更改以下内容

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" />

通过

<LinearLayout 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/renegrothmann.kalah"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" />

对我而言,它正在与之合作

<TableLayout
    android:id="@+id/resultsuperlotto"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" />

干杯!


1
投票

实际上,您不需要将xmlns:ads添加到根元素(或父元素)。

你可以简单地将xmlns:ads属性添加到你的AdView元素,如:

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    ...>
</com.google.android.gms.ads.AdView>

检查this page


0
投票

也许你应该用“app”替换底部的“myapp”或者用“xmlns:myapp”替换顶部的“xmlns:app”。他们可能应该是一样的。


0
投票

我无法提供真正的答案,因为实际上我不知道,为什么现在有效。我做了什么:我重新启动了一个新项目。有时,你只是走错了一步!


0
投票

右键单击您的项目,单击属性,单击Android,在库面板上单击添加按钮,然后在项目下添加google-play-services_lib和appcompat_v7库Apply,Refresh,Clean。

如果这不起作用,请尝试以下方法:

  • 将project.properties中的目标行更改为target = android-13
  • 右键单击您的项目,然后单击“刷新”
  • 单击项目下的清洁

希望这会奏效。

© www.soinside.com 2019 - 2024. All rights reserved.