With a few changes to your code, you can combine native and banner ads in your
ad requests.

## Prerequisites

- Version 11.0.0 or higher of the Google Mobile Ads SDK.

- Complete the [Get started guide](https://developers.google.com/ad-manager/mobile-ads-sdk/android/quick-start.md.txt).

## Load an ad

Custom-rendered native ads are loaded using the `AdLoader` class, which has its
own `AdLoader.Builder` class to customize it during creation. By adding
listeners to the `AdLoader` while building it, an app specifies which types of
ad formats it is ready to receive. The `AdLoader` then requests just those
types.

The `AdLoader` object can also be configured to make ad requests that can result
in either a banner ad or a native ad. Adding an
`OnAdManagerAdViewLoadedListener` to the `AdLoader` while building it specifies
that banner ads should compete with native ads to fill the request.

The following code demonstrates how to build an `AdLoader` that can load either
a native or banner ad in a single request:

### Java

```java
AdLoader adLoader = new AdLoader.Builder(context, "/21775744923/example/native-and-banner")
    .forNativeAd(new NativeAd.OnNativeAdLoadedListener() {
      @Override
      public void onNativeAdLoaded(NativeAd nativeAd) {
        // Show the ad.
      }
    })
    .forAdManagerAdView(new OnAdManagerAdViewLoadedListener() {
      @Override
      public void onAdManagerAdViewLoaded(AdManagerAdView adView) {
        // Show the banner ad.
      }
    }, AdSize.BANNER, AdSize.MEDIUM_RECTANGLE)
    .withAdListener(new AdListener() {
      @Override
      public void onAdFailedToLoad(LoadAdError error) {
        // Handle the failure by logging, altering the UI, etc.
      }
    })
    .withAdManagerAdViewOptions(new AdManagerAdViewOptions.Builder()
      // Methods in the AdManagerAdViewOptions.Builder class can be
      // used here to specify individual options settings.
      .build())
    .build();
```

### Kotlin

```kotlin
val adLoader = AdLoader.Builder(this, "/21775744923/example/native-and-banner")
    .forNativeAd { nativeAd ->
      // Show the ad.
    }
    .forAdManagerAdView({ adView ->
      // Show the banner ad.
    }, AdSize.BANNER, AdSize.MEDIUM_RECTANGLE)
    .withAdListener(object: AdListener() {
      override fun onAdFailedToLoad(adError: LoadAdError) {
        // Handle the failure by logging, altering the UI, etc.
      }
    })
    .withAdManagerAdViewOptions(AdManagerAdViewOptions.Builder()
      // Methods in the AdManagerAdViewOptions.Builder class can be
      // used here to specify individual options settings.
      .build())
    .build()
```

The `forAdManagerAdView()` method prepares the `AdLoader` to receive banner ads.
A variable-length list of valid ad sizes must be specified alongside an
`OnAdManagerAdViewLoadedListener` when invoking `forAdManagerAdView()`.

To make a valid ad request, at least one valid ad size must be specified. When a
banner ad has loaded successfully, the specified listener object's
`onAdManagerAdViewLoaded()` method is called.

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]
> **Key Point:** Banner ads can only be loaded through `AdLoader` objects when requested alongside native ads. To make an ad request for banners alone, follow the steps outlined in the in [Banner
> Ads](https://developers.google.com/ad-manager/mobile-ads-sdk/android/banner). In addition, banners loaded through `AdLoader` objects don't refresh.

## Set the AdViewOptions object

The last function included in the creation of the `AdLoader` is another optional
method, `withAdManagerAdViewOptions()`:

### Java

```java
.withAdManagerAdViewOptions(new AdManagerAdViewOptions.Builder()
    // Methods in the AdManagerAdViewOptions.Builder class can be
    // used here to specify individual banner options settings.
    .build()
```

### Kotlin

```kotlin
.withAdManagerAdViewOptions(AdManagerAdViewOptions.Builder()
    // Methods in the AdManagerAdViewOptions.Builder class can be
    // used here to specify individual banner options settings.
    .build()
```

The `AdManagerAdViewOptions` object lets publishers set specific options for
banners loaded by the `AdLoader`, such as:

`setManualImpressionsEnabled()`
:   Enables manual impression reporting for Google
    Ad Manager reservations. Apps using manual impressions can determine for
    themselves when an impression should be recorded, and can do so by calling
    `AdManagerAdView.recordManualImpression()`.

<br />