<br />

Adaptive banners let you specify the width of an ad to determine the optimal
ad size for each device. Unlike anchored adaptive banners, inline adaptive
banners are larger, taller, and don't use fixed heights. Inline adaptive banners
have variable height. These banners might fill the entire screen or a maximum
height you specify.

This guide covers creating inline adaptive banners and setting the banner
size.

The following image shows inline adaptive banners in scrolling content:

![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 [set up banner ads](https://developers.google.com/ad-manager/mobile-ads-sdk/android/next-gen/banner.md.txt).

To view a full inline adaptive banner example, download the following
sample app:

- [Java](https://github.com/googleads/gma-next-gen-sdk-android-examples/tree/main/java/NextGenExample/app/src/main/java/com/example/nextgenexample/inlinebanner)
- [Kotlin](https://github.com/googleads/gma-next-gen-sdk-android-examples/tree/main/kotlin/NextGenExample/app/src/main/java/com/example/nextgenexample/inlinebanner)

<br />

## Implement inline adaptive banners

To implement inline adaptive banners, you set the ad size, create an ad request,
and load the ad.

To size an inline adaptive banner, determine the ad width. Common approaches
include the following:

- Using the full-screen width.
- Using the width of the parent layout containing the ad.
- Adjusting the width to account for device safe areas.

When creating the ad size object, use this calculated width.

The following example sets the ad size, creates an ad request, and loads the ad:

### Kotlin

```kotlin
private fun loadInlineAdaptiveBannerAd(adView: AdView, activity: Activity) {
  // Create an inline adaptive ad size. 320 is a placeholder value.
  // Replace 320 with your banner container width.
  val bannerWidth = 320
  val adSize = AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(activity, bannerWidth)
  val adRequest = BannerAdRequest.Builder(AD_UNIT_ID, adSize).build()

  adView.loadAd(
    adRequest,
    object : AdLoadCallback<BannerAd> {
      override fun onAdLoaded(ad: BannerAd) {
        Log.d(TAG, "Inline adaptive banner ad loaded.")
      }

      override fun onAdFailedToLoad(adError: LoadAdError) {
        Log.d(TAG, "Inline adaptive banner ad failed to load: $adError")
      }
    },
  )
}
```

### Java

```java
private void loadInlineAdaptiveBannerAd(@NonNull AdView adView, @NonNull Activity activity) {
  // Create an inline adaptive ad size. 320 is a placeholder value.
  // Replace 320 with your banner container width.
  int bannerWidth = 320;
  AdSize adSize = AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(activity, bannerWidth);
  BannerAdRequest adRequest = new BannerAdRequest.Builder(AD_UNIT_ID, adSize).build();

  adView.loadAd(
      adRequest,
      new AdLoadCallback<BannerAd>() {
        @Override
        public void onAdLoaded(@NonNull BannerAd bannerAd) {
          Log.d(TAG, "Inline adaptive banner ad loaded.");
        }

        @Override
        public void onAdFailedToLoad(@NonNull LoadAdError adError) {
          Log.d(TAG, "Inline adaptive banner ad failed to load: " + adError);
        }
      });
}
```

Replace <var class="readonly" translate="no">AD_UNIT_ID</var> with your ad unit ID.

<br />

Set an ad size smaller than or equal to the device screen size.
To determine the maximum screen size, use the
[`Resources.getDisplayMetrics`](https://developer.android.com/reference/android/content/res/Resources#getDisplayMetrics())
method. The `AdSize` object dimensions use density-independent pixels (dp). When comparing, convert the
screen size from pixels to dp.
For details about size constraints, see
[Troubleshoot unfilled impressions in Ad Manager](https://support.google.com/admanager/answer/1739296).


> [!IMPORTANT]
> **Important:** You can serve Ad Manager reservation ad sizes in the same ad slot as adaptive banner sized ads.

If you need to update or create line items to use adaptive banners, see
[Set up line items for adaptive banners](https://support.google.com/admanager/answer/9464128).

## Set the inline adaptive banner layout

To preload an inline adaptive banner ad for a specific layout, use the
following methods:

- [`AdSize.getPortraitInlineAdaptiveBannerAdSize(Context context, int width)`](https://developers.google.com/ad-manager/mobile-ads-sdk/android/next-gen/reference/com/google/android/libraries/ads/mobile/sdk/banner/AdSize.md.txt#getPortraitInlineAdaptiveBannerAdSize(android.content.Context,kotlin.Int))

- [`AdSize.getLandscapeInlineAdaptiveBannerAdSize(Context context, int width)`](https://developers.google.com/ad-manager/mobile-ads-sdk/android/next-gen/reference/com/google/android/libraries/ads/mobile/sdk/banner/AdSize.md.txt#getLandscapeInlineAdaptiveBannerAdSize(android.content.Context,kotlin.Int))

If your app supports portrait and landscape views, and you want to preload
an adaptive banner ad in the current layout, use the

[`AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(Context context, int width)`](https://developers.google.com/ad-manager/mobile-ads-sdk/android/next-gen/reference/com/google/android/libraries/ads/mobile/sdk/banner/AdSize.md.txt#getCurrentOrientationInlineAdaptiveBannerAdSize(android.content.Context,kotlin.Int))
method.
This method loads an ad in the current layout.

### Limit inline adaptive banner height

By default, inline adaptive banners created without a `maxHeight` value
have a maximum height 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/next-gen/reference/com/google/android/libraries/ads/mobile/sdk/banner/AdSize.md.txt#getInlineAdaptiveBannerAdSize(kotlin.Int,kotlin.Int))

method.