AdMob in android “AdView missing required XML attribute 'adSize' ”

我们两清 提交于 2019-12-22 09:09:48

问题


I am trying to implement AdMob in my Application. But dont know somehow its showing this error and my R.java file is not being generated due to it. I have tried all the ways to solve this problem, like Clean,Build, Build All. But non is working for me. Following my code snippet in which its showing error "Error in parsing XML: Unbound prefix"

<?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>

Please help me out. I am stuck here :(


回答1:


Probably a namespace issue. You have to define the namespace.

try adding

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




回答2:


New Admob SDK (Google Play services) requiried another namespace

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



回答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>

and put this lines in manifest.xml file

  <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" />

the above code is working perfectly for me... visit this site for complete reference help forandroid-admob
Thanks Pragna



来源:https://stackoverflow.com/questions/7185335/admob-in-android-adview-missing-required-xml-attribute-adsize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!