2016-03-05 58 views
2

我正在嘗試使用Admob將廣告放入我的應用中。「adSize」不見了

但是,即使該屬性位於我的XML文件中,它仍然會說「必需的XML屬性」adSize「丟失」。

<com.google.android.gms.ads.AdView 
    android:id="@+id/adView" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    ads:adUnitId="MY UNIT ID" 
    ads:adSize="BANNER" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentEnd="true" /> 

是否有人知道爲什麼會發生這種情況?

乾杯。

+0

你佈局有xmlns:ads =「http://schemas.android.com/apk/libs/com.google.ads」? – W0rmH0le

回答

2

確保您的佈局有,xmlns:ads="http://schemas.android.com/apk/res-auto"屬性,也就是爲什麼你必須layout_widthfill_parent代替wrap_content,所以嘗試改變這一點。

如果您還沒有看過this tutorial。主要有activity_main.xml

你的整個XML佈局文件也會幫助找出問題。您可以刪除不想要發佈

OR,試着改變你的聲明如下,從this answer內容:

<com.google.android.gms.ads.AdView 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:id="@+id/adView" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
ads:adUnitId="YOUR_AD_UNIT_ID" 
ads:adSize="BANNER"/> 

人也建議重新啓動IDE

+0

這是導致問題的layout_width。感謝您的幫助。 –

+0

很高興幫助:) –