Anchored adaptive banner ads

  • Adaptive banners use a user-specified width and a Google-optimized height, with height limits between 50 and 90 density-independent pixels or 15% of the device's height.

  • Adaptive banners function best when they utilize the full available width, while considering safe areas and display cutouts.

  • Testing should always be done with test ads, either using the provided test ad unit IDs or by configuring a device as a test device.

Adaptive banners provide a flexible way to display ads, with a user-specified width and a Google-optimized height. The minimum banner height is 50 density-independent pixels, while the maximum is capped at 15% of the device's height or 90 density-independent pixels, whichever is smaller.

These banners perform best when they use the full available width, but you should always consider safe areas and display cutouts that might obstruct visibility when setting the banner's width.

Prerequisites

Always test with test ads

The following sample code contains an ad unit ID which you can use to request test ads. It's been specially configured to return test ads rather than production ads for every request, making it safe to use.

However, after you've registered an app in the AdMob web interface and created your own ad unit IDs for use in your app, explicitly configure your device as a test device during development.

Android

ca-app-pub-3940256099942544/9214589741

iOS

ca-app-pub-3940256099942544/2435281174

Create an anchored adaptive banner

The following example creates an anchored adaptive banner view positioned to the bottom of the screen:

// Get the device safe width in density-independent pixels.
int deviceWidth = MobileAds.Utils.GetDeviceSafeWidth();

// Define the anchored adaptive ad size.
AdSize adaptiveSize =
    AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(deviceWidth);

// Create an anchored adaptive banner view.
bannerView = new BannerView("ANCHORED_ADAPTIVE_AD_UNIT_ID", adaptiveSize, AdPosition.Bottom);

Replace ANCHORED_ADAPTIVE_AD_UNIT_ID with your ad unit ID.

With the anchored adaptive banner view created, you can now load the banner as described in Get Started guide.