2015-06-24 69 views
0

我試圖在我的測試應用中包含廣告,當我在模擬器或設備上運行應用程序時,我得到一個橫幅添加Required XML attribute 「adSize」 was missing當我有xmlns時,缺少必需的XML屬性「adSize」:ads =「http://schemas.android.com/apk/lib/com.google.ads」set

我已經在com.google.android.gms.ads.AdView標籤中設置了xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

不確定如何解決此問題。

更多細節:Android Studio AI-141.1989493

代碼片段:

AdView mAdView = (AdView) findViewById(R.id.adView); 
mAdView.setAdSize(AdSize.BANNER); 
mAdView.setAdUnitId("ca-app-pub-xxxxx/xxxxxx"); 
AdRequest adRequest = new AdRequest.Builder() 
      .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) 
      .addTestDevice("E58D5904AA50D88E2FD63A1D1EF97B34") 
      .build(); 
mAdView.loadAd(adRequest); 

AndroidManifest.xml中

<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<activity android:name="com.google.android.gms.ads.AdActivity" 
     android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" 
     android:theme="@android:style/Theme.Translucent" /> 

activity_main.xml中

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:id="@+id/LinearLayout01"> 
<TableRow android:id="@+id/LinearLayout0"> 


<com.google.android.gms.ads.AdView 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:id="@+id/adView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    ads:adSize="BANNER" 
    ads:adUnitId="ca-app-pub-xxxxx/xxxxxx" 
    ads:loadAdOnCreate="true" 
    ads:testDevices="TEST_EMULATOR, E58D5904AA50D88E2FD63A1D1EF97B34"> 
</com.google.android.gms.ads.AdView> 

回答

6

變化:

的xmlns:廣告= 「http://schemas.android.com/apk/lib/com.google.ads」

要:

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

+0

謝謝,它爲我工作。 –

0

<TableRow 
    android:id="@+id/LinearLayout0" 
    xmlns:ads="http://schemas.android.com/apk/res-auto"> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="ca-app-pub-xxxxx/xxxxxx" 
     ads:loadAdOnCreate="true" 
     ads:testDevices="TEST_EMULATOR, E58D5904AA50D88E2FD63A1D1EF97B34"> 
    </com.google.android.gms.ads.AdView> 

</TableRow> 

試試這包括你的root屬性爲這裏完成。

0

下面的代碼爲我工作,我認爲這將是全方位的:

<com.google.android.gms.ads.AdView 
      xmlns:ads="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/adView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_alignParentBottom="true" 
      ads:adSize="BANNER" 
      ads:adUnitId="ca-app-pub-3940256099942544/6300978111"> 
</com.google.android.gms.ads.AdView> 
相關問題