Inline adaptive banners

Adaptive banners are the next generation of responsive ads, maximizing performance by optimizing ad size for each device. Improving on fixed-size banners, which only supported fixed heights, adaptive banners let developers specify the ad-width and use this to determine the optimal ad size.

To pick the best ad size, inline adaptive banners use maximum instead of fixed heights. This results in opportunities for improved performance.

When to use inline adaptive banners

Inline adaptive banners are larger, taller banners compared to anchored adaptive banners. They are of variable height, and can be as tall as the device screen.

They are intended to be placed in scrolling content, for example:

Before you begin

When implementing adaptive banners in your app, note these points:

  • In order for inline adaptive banners to function correctly, you need to make your layouts responsive. Failure to do so may result in cropped or incorrectly rendered ad experiences.
  • You must know the width of the view that the ad will be placed in, and this should take into account the device width and any safe areas that are applicable.

  • Ensure you are using the latest version of the Google Mobile Ads SDK, and if using mediation, the latest versions of your mediation adapters.

  • The inline adaptive banner sizes are designed to work best when using the full available width. In most cases, this will be the full width of the screen of the device in use. Be sure to take into account applicable safe areas.

  • You may need to update or create new line items to work with adaptive sizes. Learn more.

Implementation

The steps to implement inline adaptive banner ads are the same as the steps to implement anchored adaptive banner ads. The only difference is inline adaptive banner ads are loaded using an inline adaptive banner ad size. To create an inline adaptive ad size:

  • Get the width of the device in use, or set your own width if you don't want to use the full width of the screen.
  • Use the appropriate static methods on the ad size class, such as AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(Context context, int width) to get an inline adaptive ad size object for the chosen orientation.
  • If you want to limit the height of the banner, you can use the static method AdSize.getInlineAdaptiveBannerAdSize(int width, int maxHeight) .

The sample code below demonstrates these steps:

Java

// Step 1: Create an inline adaptive banner ad size using the activity context.
AdSize adSize = AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(this, 320);

// Step 2: Create banner using activity context and set the inline ad size and
// ad unit ID.
AdManagerAdView bannerView = new AdManagerAdView(this);
bannerView.setAdUnitId("ad unit ID");

// Note that this sets both the adaptive ad size for backfill inventory as well
// as the supported reservation sizes.
bannerView.setAdSizes(adSize, AdSize.BANNER);

// Step 3: Load an ad.
AdManagerAdRequest adRequest = new AdManagerAdRequest.Builder().build();
bannerView.loadAd(adRequest);
// TODO: Insert banner view in list view or scroll view, etc.

Kotlin

// Step 1: Create an inline adaptive banner ad size using the activity context.
val adSize = AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(this, 320)

// Step 2: Create banner using activity context and set the inline ad size and
// ad unit ID.
val bannerView = AdManagerAdView(this)
bannerView.adUnitId = "ad unit ID"

// Note that this sets both the adaptive ad size for backfill inventory as well
// as the supported reservation sizes.
bannerView.setAdSizes(adSize, AdSize.BANNER)

// Step 3: Load an ad.
val adRequest = AdManagerAdRequest.Builder().build()
bannerView.loadAd(adRequest)
// TODO: Insert banner view in list view or scroll view, etc.

Additional resources

Examples on GitHub

Download the sample application to see inline adaptive banners in action.

Java Kotlin