Select platform: [Android (beta)
![New](https://developers.google.com/static/admob/images/new.svg)](https://developers.google.com/ad-manager/mobile-ads-sdk/android/next-gen/banner/inline-adaptive "View this page for the Android (beta) platform docs.") [Android](https://developers.google.com/ad-manager/mobile-ads-sdk/android/banner/inline-adaptive "View this page for the Android platform docs.") [iOS](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/banner/inline-adaptive "View this page for the iOS platform docs.") [Flutter](https://developers.google.com/ad-manager/mobile-ads-sdk/flutter/banner/inline-adaptive "View this page for the Flutter platform docs.")

<br />

Adaptive banners let you specify the width of an ad to determine the optimal
ad size. Adaptive banners also maximize performance by optimizing the ad size
for each device. This approach results in opportunities for
improved performance.

Compared to anchored adaptive banners, inline adaptive banners are larger,
taller, and use variable instead of fixed heights. Inline adaptive banners are
of variable height, and might encompass the entire screen or a maximum height
that you specify.

You place inline adaptive banners in scrolling content, for example:

![Diagram showing differences in adaptive and inline adaptive banners](https://developers.google.com/static/admob/images/inline-adaptive.png)

## Before you begin

Before continuing, make sure you have completed the getting started guide,
[Banner ads](https://developers.google.com/ad-manager/mobile-ads-sdk/android/banner).

## Implement adaptive banners

Unlike anchored adaptive banners, inline adapter banners load using an inline
adaptive banner size. To create an inline adaptive ad size, complete the
following:

1. 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.

   ### Kotlin

       private val adWidth: Int
         get() {
           val displayMetrics = resources.displayMetrics
           val adWidthPixels =
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
               val windowMetrics: WindowMetrics = this.windowManager.currentWindowMetrics
               windowMetrics.bounds.width()
             } else {
               displayMetrics.widthPixels
             }
           val density = displayMetrics.density
           return (adWidthPixels / density).toInt()
         }  
       https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/kotlin/advanced/InlineAdaptiveBannerExample/app/src/main/java/com/google/android/gms/example/inlineadaptivebannerexample/MainActivity.kt#L81-L94

   ### Java

       public int getAdWidth() {
         DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
         int adWidthPixels = displayMetrics.widthPixels;

         if (VERSION.SDK_INT >= VERSION_CODES.R) {
           WindowMetrics windowMetrics = this.getWindowManager().getCurrentWindowMetrics();
           adWidthPixels = windowMetrics.getBounds().width();
         }

         float density = displayMetrics.density;
         return (int) (adWidthPixels / density);
       }  
       https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/java/advanced/InlineAdaptiveBannerExample/app/src/main/java/com/google/android/gms/example/inlineadaptivebannerexample/MainActivity.java#L133-L145

   <br />

- To get an inline adaptive ad size object for the chosen orientation, use a
  static method on the ad size class:

  ### Kotlin

      val adView = AdView(this@MainActivity)
      adView.setAdSize(AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(this, adWidth))  
      https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/kotlin/advanced/InlineAdaptiveBannerExample/app/src/main/java/com/google/android/gms/example/inlineadaptivebannerexample/MainActivity.kt#L131-L132

  ### Java

      final AdView adView = new AdView(MainActivity.this);
      adView.setAdSize(AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(this, getAdWidth()));  
      https://github.com/googleads/googleads-mobile-android-examples/blob/6252f89e35ae5b73053ed3f74bf551114920b7ad/java/advanced/InlineAdaptiveBannerExample/app/src/main/java/com/google/android/gms/example/inlineadaptivebannerexample/MainActivity.java#L154-L155

  <br />

- 
| **Important:** Ad Manager reservation ad sizes can be served in the same ad slot as adaptive banner sized ads.
- When implementing adaptive banners in your app, note these points:
  - The inline adaptive banner sizes work best when using the full available width. In most cases, this size is the full width of the device screen in use, or the full width of the banner's parent content. You must know the width of the view to place in the ad, the device width, the parent content width, and applicable safe areas.
  <!-- -->

  - You may need to update or create new line items to work with adaptive sizes. [Learn more](https://support.google.com/admanager/answer/9464128).

## Orient inline adaptive banner size

- To preload an inline adaptive banner ad for a specific orientation, use the following methods:
  - [`AdSize.getPortraitInlineAdaptiveBannerAdSize(Context context, int width)`](https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/AdSize#getPortraitInlineAdaptiveBannerAdSize(android.content.Context,int))

  - [`AdSize.getLandscapeInlineAdaptiveBannerAdSize(Context context, int width)`](https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/AdSize#getLandscapeInlineAdaptiveBannerAdSize(android.content.Context,int))

- If your app supports both portrait and landscape views, and you want to preload an adaptive banner ad in the current orientation, use [`AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(Context context, int width)`](https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/AdSize#getCurrentOrientationInlineAdaptiveBannerAdSize(android.content.Context,int)) This method loads an ad in the current orientation.

### Limit inline adaptive banner height

- By default, inline adaptive banners instantiated without a `maxHeight` value have a `maxHeight` equal to the device height. To limit the inline adaptive banner height, use the [`AdSize.getInlineAdaptiveBannerAdSize(int width, int maxHeight)`](https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/AdSize#getInlineAdaptiveBannerAdSize(int,int)) method.

## Additional resources

### Examples on GitHub

- Download the sample application to see inline adaptive banners in action.
- [Java](https://github.com/googleads/googleads-mobile-android-examples/tree/main/java/advanced/InlineAdaptiveBannerExample) [Kotlin](https://github.com/googleads/googleads-mobile-android-examples/tree/main/kotlin/advanced/InlineAdaptiveBannerExample)
-