How to make AdView “occupy” space even while requesting an ad? (Android)

后端 未结 3 1300
刺人心
刺人心 2021-02-05 15:04

I\'m using Google AdMob Ads SDK 4.0.4 for Android

By default, The AdView will have no size until the ad is loaded. Which could cause problem if you have buttons above or

3条回答
  •  清歌不尽
    2021-02-05 15:32

    First you have to decide the ad size that you want. There are a couple of pre-defined ones.

    The easiest to work with is SMART_BANNER, it will adapt it's width to match the current screen width, and it's height will be 32, 50 or 90 dp for screen heights <=400, (>400 && <=720) or >720 dp respectively.

    Once you know the type of banner you will request, you declare it on adSize property and reserve the space for this using layout_width and layout_height properties.

    For example for an SMART_BANNER you can do something like this:

    
    

    And you will set ad_banner_height to the following values:

    values/dimens/ad_banner_height --> 32dp
    values-h400dp/dimens/ad_banner_height --> 50dp
    values-h720dp/dimens/ad_banner_height --> 90dp
    

    For other banner sizes, check: https://developers.google.com/admob/android/banner#banner_sizes

提交回复
热议问题