The ad size and ad unit ID must be set before loadAd when set programmatically

前端 未结 7 1732
有刺的猬
有刺的猬 2020-12-14 00:01

I have no idea what is going on here but I am trying to set my ad unit ID dynamically through code like below and removing it from the XML but still get the error:

7条回答
  •  太阳男子
    2020-12-14 00:30

    You've got

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    

    From: https://developers.google.com/admob/android/banner#smart_banners

    Note: The smart banner view in your layout must consume the full width of the device. If it doesn't, you'll get a warning with the message "Not enough space to show ad", and the banner will not be displayed.

    change it to

    android:layout_width="match_parent"
    

    And set your adUnitID in the xml file.

    ads:adUnitId="AD_UNIT_ID"
    

提交回复
热议问题