2011-08-25 75 views
4

我试图在我的应用程序中实现AdMob。但不知道它显示这个错误,我的R.java文件并没有被生成,因为它。我尝试了所有方法来解决这个问题,比如Clean,Build,Build All。但非是为我工作。 继我的代码片段中,其示值误差“错误在解析XML:未绑定前缀”AdMob在android“AdView缺少必需的XML属性'adSize'”

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
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:orientation="vertical" 
android:background="@color/bgcolor"> 

<LinearLayout 
android:id="@+id/Linearlayout1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" > 

<com.google.ads.AdView android:id="@+id/adView" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         ads:adSize="BANNER" 
         ads:adUnitId="XXX" 
         ads:refreshInterval="60"/> 


</LinearLayout> 

请帮助我。我在这里停留:(

回答

16

可能是一个命名空间的问题。你必须定义的命名空间。

尝试添加

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

+0

我尝试添加上述行,但后来也是其无法正常工作。对于上面的工作,我是否还必须在'res'目录中创建'lib'文件夹并将AdMob jar复制到它? – YuDroid

+0

后来当我再次重建并清理该项目时,上面的解决方案为我工作。感谢Eren – YuDroid

+0

还有一件事要做,就是当我在使用'libs'文件夹尝试上述代码时,广告没有得到显示。但是当我将它改为'lib'时,它的工作没有麻烦。 – YuDroid

3
<?xml version="1.0" encoding="utf-8"?> 
<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:id="@+id/rltvLayoutPromote" 
    android:layout_height="fill_parent"> 
    <LinearLayout android:id="@+id/linearLayoutwebview" 
     android:layout_height="wrap_content" android:layout_width="wrap_content" 
     android:orientation="vertical"> 
     <WebView android:id="@+id/webViewPromote" 
      android:layout_width="fill_parent" android:layout_height="fill_parent" 
      android:fitsSystemWindows="true" /> 
    </LinearLayout> 
    <LinearLayout android:layout_width="fill_parent" 
     android:id="@+id/ad_layout" android:layout_height="wrap_content" 
     android:gravity="bottom" android:layout_alignParentBottom="true" 
     android:layout_alignBottom="@+id/home_layout"> 
     <com.google.ads.AdView android:layout_width="wrap_content" 
      android:layout_height="wrap_content" ads:adUnitId="XXXXXXXXXX" 
      ads:adSize="BANNER" android:id="@+id/adView" ads:refreshInterval="60" /> 
     <!--   put 3 if not working--> 
    </LinearLayout> 
</RelativeLayout> 

,并把此行manifest.xml文件

<uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <meta-data android:value="true" android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" /> 

上述代码对我来说是完美的... v ISIT本网站的完整参考help forandroid-admob
感谢Pragna

+0

我想要做的是如下的小片段。你能检查它并告诉我我在哪里做错了吗? – YuDroid

+0

因为我是初学者,所以我不允许添加超出我允许的字符数限制的评论。所以我编辑了我的问题,并包含更多的代码 – YuDroid

+0

好的,让我试试你的代码 – Android

6

新版AdMob的SDK(谷歌Play服务)requiried另一个命名空间

xmlns:ads="http://schemas.android.com/apk/res-auto" 
相关问题