2014-06-20 56 views
0

我知道這個問題以前可能已被問過,但我無法使用這些答案解決我的問題。缺少XML屬性的Android廣告

我的問題是當我使用eclipse將我的AdView添加到我的佈局時,我收到消息:缺少所需的XML屬性「adSize」。

這是我目前活動XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/content" 
xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:gravity="center" 
android:orientation="vertical" > 

<android.support.v4.view.ViewPager 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/pager" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="0.9" 
    android:background="@drawable/background"> 

</android.support.v4.view.ViewPager> 

<com.google.android.gms.ads.AdView 
    xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads" 
    android:id="@+id/adView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.1" 
    ads:adSize="BANNER" 
    ads:adUnitId="mycodehidden"> 

</com.google.android.gms.ads.AdView> 

還沒有當我運行此顯示廣告。

回答

0

你正在合併舊的和新的admob apis這是錯誤的。

通過谷歌Play服務庫使用AdMob,更改廣告XML命名空間:

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

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

然後在清單中的應用標籤:

<activity android:name="com.google.android.gms.ads.AdActivity" 
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 


<meta-data android:name="com.google.android.gms.version" 
       android:value="@integer/google_play_services_version"/> 

不要忘了權限:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="android.permission.INTERNET"/>