2016-05-12 71 views
0

我正在實施橫幅廣告,但收到錯誤「必需的XML屬性」adsize「缺失」。我用the developer.google.com link to add admob顯示錯誤必填XML屬性「adSize」丟失

我還訪問了其他計算器的問題,如爲Required XML attribute 'adsize' was missing (google play service)

和但錯誤是一樣的我已經實現了一切。這是代碼。

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.example.abhishek.canddatastructureprograms.MainActivity"> 



<FrameLayout 
    android:id="@+id/sample_content_fragment" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

<com.google.android.gms.ads.AdView 
    android:id="@+id/adView" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:layout_centerHorizontal="true" 
    android:layout_alignParentBottom="true" 
    ads:adSize="BANNER" 
    ads:adUnitId="@string/banner_ad_unit_id"> 

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

MainActivity.java

在的onCreate加入下列代碼()方法。

AdView mAdview= (AdView) findViewById(R.id.adView); 


    //AdRequest mAdRequest= new AdRequest().Builder.build(); 

    AdRequest request = new AdRequest.Builder() 
      .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)  // All emulators 
      .addTestDevice("9F099BD5E5700664591DEC5FDC92A40E") // An example device ID 
      .build(); 

    mAdview.loadAd(request); 

請讓我知道如果我需要添加任何更多的細節或代碼。

回答

0

代碼似乎是正確的。嘗試刪除所有左側和右側填充或邊距,也許你會得到這個錯誤,因爲你有太小的屏幕來顯示添加。

+0

哇!非常感謝!!它現在有效。我甚至從未想過這會影響它。 –

相關問題