【问题标题】:"adSize" was missing缺少“adSize”
【发布时间】:2016-03-05 22:13:07
【问题描述】:

我正在尝试使用 Admob 在我的应用中投放广告。

但是,它一直说“缺少必需的 XML 属性“adSize””,即使该属性在我的 XML 文件中。

    <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" />

有人知道为什么会这样吗?

干杯。

【问题讨论】:

标签: android-studio admob google-play-services


【解决方案1】:

确保您的布局具有xmlns:ads="http://schemas.android.com/apk/res-auto" 属性,以及为什么您将layout_width 设置为fill_parent 而不是wrap_content,所以也尝试更改它。

如果您还没有,请查看this tutorial。主要有activity_main.xml

您的整个 XML 布局文件也将有助于找出问题所在。您可以删除不想发布的内容

或者,尝试将您的声明从 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

【讨论】:

  • 这是导致问题的 layout_width。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 2011-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多