Skip to end of metadata
Go to start of metadata

Resize Ads to fit the Screen or Banner Ad View

Depending on where advertising fits into your application, you might want to expand the ad creative to fill the banner ad view in which it is displayed, or to fit the device's screen width.

This page has instructions for:

  • Resizing the ad to fill the banner ad view
  • Resizing the ad to fit the device's screen width
  • Constraining the ad the the container view (superview)
On This Page

iOS

Resize Ad to Fit the Banner Ad View

Properties

PropertyDescription
shouldResizeAdToFitContainer

Determines whether the creative should resize to fill the banner ad view in which it is displayed. This feature will cause ad creatives that are smaller than the view size to 'stretch' to the current size. This may cause image quality degradation for the benefit of having an ad occupy the entire ad view. Defaults to NO.

Example

Constrain to the Container View

By default ANBannerAdView is set to constrain to the size of the creative that is returned. But for some custom sizes you might want the ANBannerAdView to be constrained to its superview.

By adding the custom sizes to sizesThatShouldConstrainToSuperview array you can instruct the SDK to set the right constraints for you. 

sizesThatShouldConstrainToSuperview is a Global setting and will be applied to all of the Banner Ad Views in your app.


Properties

PropertyDescription
sizesThatShouldConstrainToSuperviewSpecial ad sizes for which the ANBannerAdView should be constrained to its super view.

Example

Android

Resize Ad to Fit the Banner Ad View

Methods

MethodDescription
setResizeAdToFitContainer(boolean)

Whether the creative should resize to fill the banner ad view in which it is displayed. This feature will cause ad creatives that are smaller than the view size to 'stretch' to the current size. This may cause image quality degradation for the benefit of having an ad occupy the entire ad view. Defaults to false.

getResizeAdToFitContainer()

Check whether the creative will resize to fill the banner ad view in which it is displayed.

Example

Resize Ad to Fit the Screen Width

Methods

MethodDescription
setExpandsToFitScreenWidth(boolean)

Causes the banner ad view to resize to fit the width of the device's screen. This feature will cause ad creatives that are smaller than the screen width to 'stretch' to fit. This may cause image quality degradation for the benefit of having an ad occupy the entire screen. Defaults to false.

getExpandsToFitScreenWidth()

Check whether the banner ad view will resize to fit the width of the device's screen.

Example

Put Them Together

If you call both setExpandsToFitScreenWidth(true) and setResizeAdToFitContainer(true), the SDK will try to expand the banner ad view to the screen width first, and then adjust the ad to fit the container size.

Related Topics