2012-02-01 99 views
1

我試圖使用下面的代碼顯示添加。 我收到錯誤「AdView缺少所需xml屬性adSize」。AdView缺少所需的xml屬性adSize

什麼問題?

的main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:ads="http://schemas.android.com/apk/res/com.jms.AdmobExample" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

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

attr.xml:

<?xml version="1.0" encoding="utf-8"?> 
    <resources> 
    <declare-styleable name="com.google.ads.AdView"> 
    <attr name="adSize"> 
    <enum name="BANNER" value="1"/> 
    <enum name="IAB_MRECT" value="2"/> 
    <enum name="IAB_BANNER" value="3"/> 
    <enum name="IAB_LEADERBOARD" value="4"/> 
    </attr> 
    <attr name="adUnitId" format="string"/> 
</declare-styleable> 
</resources> 

回答

3

使用本

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res/com.jms.AdmobExample" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <com.google.ads.AdView 
     xmlns:ads="http://schemas.android.com/apk/res/com.jms.AdmobExample" 
     android:id="@+id/add_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"    
     ns:adSize="BANNER" 
     ns:adUnitId="a14f1d807e488dd" > 
    </com.google.ads.AdView> 

</Linearlayout> 
+0

你好我使用你的發送相同的代碼,但得到同樣的錯誤。 – user1089640 2012-02-02 05:55:39

+0

我們也用Java編寫的文件 – NagarjunaReddy 2012-02-02 06:01:18

0

看來你adSize時屬性不被認可。

我想說,無論是你的命名空間屬性的問題(加吧),要麼,你應該檢查一下你叫attr.xml「attrs.xml」,因爲它應該是。

注意this說attrs.xml是沒有必要使用AdMob的新版本。

+0

我已經添加adSize時attribute.what烏爾說rolldnums我沒有得到 – user1089640 2012-02-02 05:57:19

+0

那麼你可能需要添加命名空間中領域:xmlns:廣告=「http://schemas.android.com/apk /res/com.jms.AdmobExample「。檢查http://stackoverflow.com/questions/5613398/admob-missing-required-xml-attribute-adunitid,因爲錯誤似乎發生在相同的條件。 – Kheldar 2012-02-02 08:32:40

0

你缺少這樣的xml文件:

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

,使其與谷歌工作中發揮服務使用:

的xmlns:廣告=「http://schemas.android.com/apk/RES-AUTO」

在XML文件中