Banner and MREC ads are rectangular ad formats that occupy part of an app’s layout—often at the top or bottom of the screen or inline in scrollable content. They remain visible as users interact with the app, which allows uninterrupted gameplay or use, and can refresh automatically after a set period.
The following sections show you how to load, show, and hide a banner or MREC ad.
“Why mobile banners ads persist in a video and playable world” from AppLovin’s Blog.
To load a banner or MREC, create a MaxAdView object that corresponds to your ad unit.
Then call that object’s loadAd() method.
To show that ad, add the MaxAdView object as a subview of your view hierarchy.
Implement MaxAdViewAdListener so that you are notified when your ad is ready (you will also be notified of other ad-related events).
If your integration requires displaying MREC ads in a content feed, AppLovin recommends the following:
loadAd() (re-use the MaxAdView instances).You can find an example implementation in the AppLovin demo app (Java, Kotlin).
public class ExampleActivity extends Activity
implements MaxAdViewAdListener
{
private MaxAdView adView;
void createBannerAd()
{
adView = new MaxAdView( "«ad-unit-ID»", this );
adView.setListener( this );
// Stretch to the width of the screen for banners to be fully functional
int width = ViewGroup.LayoutParams.MATCH_PARENT;
// Banner height on phones and tablets is 50 and 90, respectively
int heightPx = getResources().getDimensionPixelSize( R.dimen.banner_height );
adView.setLayoutParams( new FrameLayout.LayoutParams( width, heightPx ) );
// Set background color for banners to be fully functional
adView.setBackgroundColor( «background-color» );
ViewGroup rootView = findViewById( android.R.id.content );
rootView.addView( adView );
// Load the ad
adView.loadAd();
}
// MAX Ad Listener
@Override
public void onAdLoaded(final MaxAd maxAd) {}
@Override
public void onAdLoadFailed(final String adUnitId, final MaxError error) {}
@Override
public void onAdDisplayFailed(final MaxAd maxAd, final MaxError error) {}
@Override
public void onAdClicked(final MaxAd maxAd) {}
@Override
public void onAdExpanded(final MaxAd maxAd) {}
@Override
public void onAdCollapsed(final MaxAd maxAd) {}
@Override
public void onAdDisplayed(final MaxAd maxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
@Override
public void onAdHidden(final MaxAd maxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
}class ExampleActivity : Activity(), MaxAdViewAdListener
{
private var adView: MaxAdView? = null
fun createBannerAd()
{
adView = MaxAdView("«ad-unit-ID»", this)
adView?.setListener(this)
// Stretch to the width of the screen for banners to be fully functional
val widthPx = ViewGroup.LayoutParams.MATCH_PARENT
// Banner height on phones and tablets is 50 and 90, respectively
val heightPx = resources.getDimensionPixelSize(R.dimen.banner_height)
adView?.layoutParams = FrameLayout.LayoutParams(widthPx, heightPx)
// Set background color for banners to be fully functional
adView?.setBackgroundColor(«background-color»)
val rootView = findViewById(android.R.id.content)
rootView.addView(adView)
// Load the ad
adView?.loadAd()
}
// MAX Ad Listener
override fun onAdLoaded(maxAd: MaxAd) {}
override fun onAdLoadFailed(adUnitId: String?, error: MaxError?) {}
override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?) {}
override fun onAdClicked(maxAd: MaxAd) {}
override fun onAdExpanded(maxAd: MaxAd) {}
override fun onAdCollapsed(maxAd: MaxAd) {}
override fun onAdDisplayed(maxAd: MaxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
override fun onAdHidden(maxAd: MaxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
}public class ExampleActivity extends Activity
implements MaxAdViewAdListener
{
private MaxAdView adView;
void createMRecAd()
{
adView = new MaxAdView( "«ad-unit-ID»", MaxAdFormat.MREC, this );
adView.setListener( this );
// MREC width and height are 300 and 250 respectively, on phones and tablets
int widthPx = AppLovinSdkUtils.dpToPx( this, 300 );
int heightPx = AppLovinSdkUtils.dpToPx( this, 250 );
adView.setLayoutParams( new FrameLayout.LayoutParams( widthPx, heightPx ) );
// Set background color for MRECs to be fully functional
adView.setBackgroundColor( «background-color» );
ViewGroup rootView = findViewById( android.R.id.content );
rootView.addView( adView );
// Load the ad
adView.loadAd();
}
// MAX Ad Listener
@Override
public void onAdLoaded(final MaxAd maxAd) {}
@Override
public void onAdLoadFailed(final String adUnitId, final MaxError error) {}
@Override
public void onAdDisplayFailed(final MaxAd maxAd, final MaxError error) {}
@Override
public void onAdClicked(final MaxAd maxAd) {}
@Override
public void onAdExpanded(final MaxAd maxAd) {}
@Override
public void onAdCollapsed(final MaxAd maxAd) {}
@Override
public void onAdDisplayed(final MaxAd maxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
@Override
public void onAdHidden(final MaxAd maxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
}class ExampleActivity : Activity(), MaxAdViewAdListener
{
private var adView: MaxAdView? = null
fun createMRecAd()
{
adView = MaxAdView("«ad-unit-ID»", MaxAdFormat.MREC, this)
adView?.setListener(this)
// MREC width and height are 300 and 250 respectively, on phones and tablets
val widthPx = AppLovinSdkUtils.dpToPx(this, 300)
val heightPx = AppLovinSdkUtils.dpToPx(this, 250)
adView?.layoutParams = FrameLayout.LayoutParams(widthPx, heightPx)
// Set background color for MRECs to be fully functional
adView?.setBackgroundColor(«background-color»)
val rootView = findViewById(android.R.id.content)
rootView.addView(adView)
// Load the ad
adView?.loadAd()
}
// MAX Ad Listener
override fun onAdLoaded(maxAd: MaxAd) {}
override fun onAdLoadFailed(adUnitId: String?, error: MaxError?) {}
override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?) {}
override fun onAdClicked(maxAd: MaxAd) {}
override fun onAdExpanded(maxAd: MaxAd) {}
override fun onAdCollapsed(maxAd: MaxAd) {}
override fun onAdDisplayed(maxAd: MaxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
override fun onAdHidden(maxAd: MaxAd) { /* DO NOT USE - THIS IS RESERVED FOR FULLSCREEN ADS ONLY AND WILL BE REMOVED IN A FUTURE SDK RELEASE */ }
}You can also add MAX banners or MRECs to your view layout XML.
Ensure that your ads are fully functional by setting a background or background color (android:background).
For banners, stretch the width (android:layout_width) to the width of the screen.
For MRECs, set android:adFormat accordingly:
<com.applovin.mediation.ads.MaxAdView
xmlns:maxads="http://schemas.applovin.com/android/1.0"
maxads:adUnitId="«ad-unit-ID»"
android:background="@color/banner_background_color"
android:layout_width="match_parent"
android:layout_height="@dimen/banner_height" />
Declare the base banner height of 50 dp in res/values/attrs.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="banner_height">50dp</dimen>
</resources>
Declare the tablet banner height of 90 dp in res/values-sw600dp/attrs.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="banner_height">90dp</dimen>
</resources><com.applovin.mediation.ads.MaxAdView
xmlns:maxads="http://schemas.applovin.com/android/1.0"
maxads:adUnitId="«ad-unit-ID»"
maxads:adFormat="MREC"
android:background="@color/mrec_background_color"
android:layout_width="300dp"
android:layout_height="250dp" />You still must call loadAd() on the MaxAdView you create in this way:
MaxAdView adView = findViewById( R.id.ad_view );
adView.loadAd();var adView: MaxAdView = findViewById(R.id.ad_view)
adView.loadAd()If you no longer need a MaxAdView instance, call its destroy() method to free resources.
This may be the case, for example, if the user purchases ad removal.
Do not call the destroy() method if you use multiple instances with the same Ad Unit ID.
adView.destroy();
adView.destroy()
Google bidding and Google AdMob, Google Ad Manager, Liftoff Monetize, Pangle, and Yandex support adaptive banners. MAX sizes banners from other networks in the non-adaptive way.
Google recommends that developers include a 50 px padding between the banner placement and the app content. This makes it less likely that users accidentally click the banner. Refer to Google’s “About Confirmed Click” policy for more information and best practices.
Adaptive banners are responsive ads that dynamically adjust their dimensions based on device type and available width. Adaptive banners can be either anchored or inline, with each type serving specific integration needs.
Starting in MAX SDK version 13.2.0, you can integrate adaptive banners by initializing your MaxAdView with a MaxAdViewConfiguration object for which you set an adaptive type at build-time.
The following adapters support special adaptive banner features:
| Network | Adapter Versions | Special Feature |
|---|---|---|
| Google Ad Manager | 23.2.0.1+ | Inline adaptive banners |
| 23.6.0.3+ | Inline adaptive MRECs | |
| 21.5.0.2+ | Setting a custom width | |
| Google Bidding and Google AdMob | 23.2.0.1+ | Inline adaptive banners |
| 23.6.0.3+ | Inline adaptive MRECs | |
| 21.5.0.3+ | Setting a custom width | |
| Liftoff Monetize | 7.4.3.2+ | |
| Pangle | 7.1.0.4.0+ | |
| Yandex | 7.12.2.1+ |
Anchored adaptive banners are those you anchor at the top or bottom of the screen. They dynamically adjust their height based on the device type and the banner width.
You must set the height of the MaxAdView to the value returned by MaxAdFormat.BANNER.getAdaptiveSize( Context ).getHeight() instead of using a constant value like 50 or 90.
void createAnchoredAdaptiveBannerAd()
{
// Stretch to the width of the screen for banners to be fully functional
int widthPx = ViewGroup.LayoutParams.MATCH_PARENT;
// Get the anchored adaptive banner height
int heightDp = MaxAdFormat.BANNER.getAdaptiveSize( this ).getHeight();
int heightPx = AppLovinSdkUtils.dpToPx( this, heightDp );
MaxAdViewConfiguration config = MaxAdViewConfiguration.builder()
.setAdaptiveType( MaxAdViewConfiguration.AdaptiveType.ANCHORED )
.build();
adView = new MaxAdView( "«ad-unit-ID»", config );
adView.setListener( this );
adView.setLayoutParams( new FrameLayout.LayoutParams( widthPx, heightPx ) );
// Set background color for banners to be fully functional
adView.setBackgroundColor( «background-color» );
ViewGroup rootView = findViewById( android.R.id.content );
rootView.addView( adView );
// Load the ad
adView.loadAd();
}fun createAnchoredAdaptiveBannerAd()
{
// Stretch to the width of the screen for banners to be fully functional
val widthPx = ViewGroup.LayoutParams.MATCH_PARENT
// Get the anchored adaptive banner height
val heightDp = MaxAdFormat.BANNER.getAdaptiveSize(this).height
val heightPx = AppLovinSdkUtils.dpToPx(this, heightDp)
val config = MaxAdViewConfiguration.builder()
.setAdaptiveType( MaxAdViewConfiguration.AdaptiveType.ANCHORED )
.build();
adView = MaxAdView("«ad-unit-ID»", config)
adView?.setListener(this)
adView?.layoutParams = FrameLayout.LayoutParams(widthPx, heightPx)
// Set background color for banners to be fully functional
adView?.setBackgroundColor(«background-color»)
val rootView = findViewById<ViewGroup>(android.R.id.content)
rootView.addView(adView)
// Load the ad
adView?.loadAd()
}For more specific integrations, you can configure a custom width in dp by calling a MaxAdViewConfiguration builder method.
To fetch the appropriate height for your custom anchored adaptive ad, call the adaptive size API.
int widthDp = 400;
// Get the anchored adaptive banner height
int heightDp = MaxAdFormat.BANNER.getAdaptiveSize( widthDp, context ).getHeight();
MaxAdViewConfiguration config = MaxAdViewConfiguration.builder()
.setAdaptiveType( MaxAdViewConfiguration.AdaptiveType.ANCHORED )
.setAdaptiveWidth( widthDp )
.build();
adView = new MaxAdView( "«ad-unit-ID»", config );val widthDp = 400
// Get the anchored adaptive banner height
val heightDp = adView.adFormat.getAdaptiveSize(widthDp, context).height
val config = MaxAdViewConfiguration.builder()
.setAdaptiveType(MaxAdViewConfiguration.AdaptiveType.ANCHORED)
.setAdaptiveWidth(widthDp)
.build()
adView = MaxAdView("«ad-unit-ID»", config)Adaptive banners are anchored by default. You can also enable inline adaptive banners, which you can place in scrollable content. Inline adaptive banners are typically larger than anchored adaptive banners. They have variable heights that can extend to the full height of the device screen.
To enable inline adaptive banners, set the MaxAdViewConfiguration adaptive type to MaxAdViewConfiguration.AdaptiveType.INLINE as shown in the code below:
MaxAdViewConfiguration config = MaxAdViewConfiguration.builder()
.setAdaptiveType( MaxAdViewConfiguration.AdaptiveType.INLINE )
⋮
.build();val config = MaxAdViewConfiguration.builder()
.setAdaptiveType(MaxAdViewConfiguration.AdaptiveType.INLINE)
⋮
.build()The default maximum height for an inline adaptive ad is the entire height of the device screen.
You may want to set a maximum height, in dp, for your inline adaptive ad to ensure that the ad fits in the height of the MaxAdView.
You can do this with code like the following, which uses a maximum height of 100 dp as an example:
MaxAdViewConfiguration config = MaxAdViewConfiguration.builder()
.setAdaptiveType( MaxAdViewConfiguration.AdaptiveType.INLINE )
.setInlineMaximumHeight( 100 )
⋮
.build();val config = MaxAdViewConfiguration.builder()
.setAdaptiveType(MaxAdViewConfiguration.AdaptiveType.INLINE)
.setInlineMaximumHeight( 100 )
⋮
.build()Inline adaptive MRECs span the full width of the application window by default, but you may optionally specify a custom width in dp. The height is variable and can extend beyond standard MREC dimensions up to the full height of the device screen if you do not specify a maximum height.
Configure an inline adaptive MREC with the adaptive type set to MaxAdViewConfiguration.AdaptiveType.INLINE as shown in the following example:
void createInlineAdaptiveMRecAd()
{
// Set a custom width, in dp, for the inline adaptive MREC. Otherwise stretch to screen width by using ViewGroup.LayoutParams.MATCH_PARENT
int widthDp = 400;
int widthPx = AppLovinSdkUtils.dpToPx( this, widthDp );
// Set a maximum height, in dp, for the inline adaptive MREC. Otherwise use standard MREC height of 250 dp
// Google recommends a height greater than 50 dp, with a minimum of 32 dp and a maximum equal to the screen height
// The value must also not exceed the height of the MaxAdView
int heightDp = 300;
int heightPx = AppLovinSdkUtils.dpToPx( this, heightDp );
MaxAdViewConfiguration config = MaxAdViewConfiguration.builder()
.setAdaptiveType( MaxAdViewConfiguration.AdaptiveType.INLINE )
.setAdaptiveWidth( widthDp ) // Optional: The adaptive ad spans the width of the application window if you do not set a value
.setInlineMaximumHeight( heightDp ) // Optional: The maximum height is the screen height if you do not set a value
.build();
adView = new MaxAdView( "«ad-unit-ID»", MaxAdFormat.MREC, config );
adView.setListener( this );
adView.setLayoutParams( new FrameLayout.LayoutParams( widthPx, heightPx ) );
// Set background color for adaptive MRECs to be fully functional
adView.setBackgroundColor( «background-color» );
ViewGroup rootView = findViewById( android.R.id.content );
rootView.addView( adView );
// Load the ad
adView.loadAd();
}fun createInlineAdaptiveMRecAd()
{
// Set a custom width, in dp, for the inline adaptive MREC. Otherwise stretch to screen width by using ViewGroup.LayoutParams.MATCH_PARENT
val widthDp = 400
val widthPx = AppLovinSdkUtils.dpToPx(this, widthDp)
// Set a maximum height, in dp, for the inline adaptive MREC. Otherwise use standard MREC height of 250 dp
// Google recommends a height greater than 50 dp, with a minimum of 32 dp and a maximum equal to the screen height
// The value must also not exceed the height of the MaxAdView
val heightDp = 300
val heightPx = AppLovinSdkUtils.dpToPx( this, heightDp )
val config = MaxAdViewConfiguration.builder()
.setAdaptiveType(MaxAdViewConfiguration.AdaptiveType.INLINE)
.setAdaptiveWidth(widthDp) // Optional: The adaptive ad spans the width of the application window if a value is not specified
.setInlineMaximumHeight(heightDp) // Optional: The maximum height is the screen height if a value is not specified
.build()
adView = MaxAdView("«ad-unit-ID»", MaxAdFormat.MREC, config)
adView?.setListener(this)
adView?.layoutParams = FrameLayout.LayoutParams(widthPx, heightPx)
// Set background color for adaptive MRECs to be fully functional
adView?.setBackgroundColor(«background-color»)
val rootView = findViewById(android.R.id.content)
rootView.addView(adView)
// Load the ad
adView?.loadAd()
}The adaptive ad you load could be smaller than the dimensions you requested. You may wish to configure your UI in a way that can adapt based on the size of the adaptive ad served. If so, you can retrieve the width and height of the loaded ad, in dp, with code like the following:
@Override
public void onAdLoaded(final MaxAd maxAd)
{
AppLovinSdkUtils.Size adViewSize = maxAd.getSize();
int widthDp = adViewSize.getWidth();
int heightDp = adViewSize.getHeight();
⋮
}override fun onAdLoaded(ad: MaxAd?)
{
val adViewSize = ad?.size!!
val widthDp = adViewSize.width
val heightDp = adViewSize.height
⋮
}You may want to stop auto-refresh for an ad. This may be the case when you hide an ad or when you want to manually refresh. Stop auto-refresh with the following code:
// Set this extra parameter to work around SDK bug that ignores calls to stopAutoRefresh()
adView.setExtraParameter( "allow_pause_auto_refresh_immediately", "true" );
adView.stopAutoRefresh();// Set this extra parameter to work around SDK bug that ignores calls to stopAutoRefresh()
adView.setExtraParameter( "allow_pause_auto_refresh_immediately", "true" )
adView.stopAutoRefresh()Start auto-refresh for an ad with the following code:
adView.startAutoRefresh();
adView.startAutoRefresh()
Manually refresh the ad contents by calling loadAd().
You can do this only if you first stop auto-refresh.
adView.loadAd();
adView.loadAd()