AdSize

public final class AdSize


The size of a banner ad.

May be one of a predefined set of sizes (e.g. LARGE_BANNER), a custom size via AdSize, or an adaptive size via, e.g. getLandscapeAnchoredAdaptiveBannerAdSize.

Summary

Constants

static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

Public fields

static final @NonNull AdSize

Mobile Marketing Association (MMA) banner ad size (320x50 density-independent pixels).

static final @NonNull AdSize

A dynamically sized banner that matches its parent's width and expands/contracts its height to match the ad's content after loading completes.

static final @NonNull AdSize

Interactive Advertising Bureau (IAB) full banner ad size (468x60 density-independent pixels).

static final @NonNull AdSize

Large banner ad size (320x100 density-independent pixels).

static final @NonNull AdSize

Interactive Advertising Bureau (IAB) leaderboard ad size (728x90 density-independent pixels).

static final @NonNull AdSize

Interactive Advertising Bureau (IAB) medium rectangle ad size (300x250 density-independent pixels).

Public constructors

AdSize(int width, int height)

Creates a new AdSize.

Public methods

boolean
equals(Object other)
static final @NonNull AdSize

Returns an AdSize with the given width and a Google-optimized height to create a banner ad.

static final @NonNull AdSize

Returns an AdSize with the given width and a height of 0.

final @NonNull String
final int
final int

Returns the height of this AdSize in physical pixels.

static final @NonNull AdSize
getInlineAdaptiveBannerAdSize(int width, int maxHeight)

Returns an AdSize with the given width and a height of 0.

static final @NonNull AdSize
getLandscapeAnchoredAdaptiveBannerAdSize(
    @NonNull Context context,
    int width
)

Returns an AdSize with the given width and a Google-optimized height to create a banner ad.

static final @NonNull AdSize
getLandscapeInlineAdaptiveBannerAdSize(
    @NonNull Context context,
    int width
)

Returns an AdSize with the given width and a height of 0.

static final @NonNull AdSize
getPortraitAnchoredAdaptiveBannerAdSize(
    @NonNull Context context,
    int width
)

Returns an AdSize with the given width and a Google-optimized height to create a banner ad.

static final @NonNull AdSize
getPortraitInlineAdaptiveBannerAdSize(
    @NonNull Context context,
    int width
)

Returns an AdSize with the given width and a height of 0.

final int
final int

Returns the width of this AdSize in physical pixels.

int
final boolean
final boolean

Returns whether this AdSize is of fluid size or not.

final boolean
@NonNull String

Constants

public static final int BANNER_HEIGHT = 50
public static final int BANNER_WIDTH = 320

FULL_BANNER_HEIGHT

public static final int FULL_BANNER_HEIGHT = 60

FULL_BANNER_WIDTH

public static final int FULL_BANNER_WIDTH = 468

LARGE_BANNER_HEIGHT

public static final int LARGE_BANNER_HEIGHT = 100

LARGE_BANNER_WIDTH

public static final int LARGE_BANNER_WIDTH = 320

LEADERBOARD_HEIGHT

public static final int LEADERBOARD_HEIGHT = 90

LEADERBOARD_WIDTH

public static final int LEADERBOARD_WIDTH = 728

MEDIUM_RECTANGLE_HEIGHT

public static final int MEDIUM_RECTANGLE_HEIGHT = 250

MEDIUM_RECTANGLE_WIDTH

public static final int MEDIUM_RECTANGLE_WIDTH = 300

Public fields

BANNER

public static final @NonNull AdSize BANNER

Mobile Marketing Association (MMA) banner ad size (320x50 density-independent pixels).

FLUID

public static final @NonNull AdSize FLUID

A dynamically sized banner that matches its parent's width and expands/contracts its height to match the ad's content after loading completes.

FULL_BANNER

public static final @NonNull AdSize FULL_BANNER

Interactive Advertising Bureau (IAB) full banner ad size (468x60 density-independent pixels).

LARGE_BANNER

public static final @NonNull AdSize LARGE_BANNER

Large banner ad size (320x100 density-independent pixels).

LEADERBOARD

public static final @NonNull AdSize LEADERBOARD

Interactive Advertising Bureau (IAB) leaderboard ad size (728x90 density-independent pixels).

MEDIUM_RECTANGLE

public static final @NonNull AdSize MEDIUM_RECTANGLE

Interactive Advertising Bureau (IAB) medium rectangle ad size (300x250 density-independent pixels).

Public constructors

AdSize

public AdSize(int width, int height)

Creates a new AdSize.

Parameters
int width

The width of the ad in density-independent pixels.

int height

The height of the ad in density-independent pixels.

Throws
kotlin.IllegalArgumentException

If the width or height is negative.

Public methods

equals

public boolean equals(Object other)

getCurrentOrientationAnchoredAdaptiveBannerAdSize

public static final @NonNull AdSize getCurrentOrientationAnchoredAdaptiveBannerAdSize(
    @NonNull Context context,
    int width
)

Returns an AdSize with the given width and a Google-optimized height to create a banner ad. The size returned will have an aspect ratio similar to BANNER, suitable for anchoring near the top or bottom of your app. The height will never be larger than 15% of the device's height in landscape mode and never smaller than 50px. This function always returns the same height for any width / device combination.

Parameters
@NonNull Context context

Context to be used for getting screen dimensions.

int width

The requested width of the ad.

Returns
@NonNull AdSize

An AdSize object.

getCurrentOrientationInlineAdaptiveBannerAdSize

public static final @NonNull AdSize getCurrentOrientationInlineAdaptiveBannerAdSize(
    @NonNull Context context,
    int width
)

Returns an AdSize with the given width and a height of 0. This ad size allows Google servers to choose an optimal ad size less than or equal to the height of the screen in the current orientation. The exact size of the ad returned can be retrieved by calling BannerAd.getAdSize inside the AdLoadCallback.onAdLoaded callback. This ad size is most suitable for ads intended to be displayed inside scrollable content.

Parameters
@NonNull Context context

Context to be used for getting screen dimensions.

int width

The requested width of the ad.

Returns
@NonNull AdSize

An AdSize object.

getFormatString

public final @NonNull String getFormatString()

getHeight

public final int getHeight()

getHeightInPixels

public final int getHeightInPixels(@NonNull Context context)

Returns the height of this AdSize in physical pixels. For fluid size, it returns -1.

getInlineAdaptiveBannerAdSize

public static final @NonNull AdSize getInlineAdaptiveBannerAdSize(int width, int maxHeight)

Returns an AdSize with the given width and a height of 0. This ad size allows Google servers to choose an optimal ad size with a height less than or equal to the max height given in the maxHeight parameter. The exact size of the ad returned can be retrieved by calling BannerAd.getAdSize inside the AdLoadCallback.onAdLoaded callback. This ad size is most suitable for ads intended to be displayed inside scrollable content.

Parameters
int width

The requested width of the ad.

int maxHeight

The maximum height that a loaded ad will have. Must be at least 32 dp, but a maxHeight of 50 dp or higher is recommended.

Returns
@NonNull AdSize

An AdSize object.

Throws
kotlin.IllegalArgumentException

If maxHeight is not positive.

getLandscapeAnchoredAdaptiveBannerAdSize

public static final @NonNull AdSize getLandscapeAnchoredAdaptiveBannerAdSize(
    @NonNull Context context,
    int width
)

Returns an AdSize with the given width and a Google-optimized height to create a banner ad. The size returned will have an aspect ratio similar to BANNER, suitable for anchoring near the top or bottom of your app. The height will never be larger than 15% of the device's height in landscape mode and never smaller than 50px. This function always returns the same height for any width / device combination.

Parameters
@NonNull Context context

Context to be used for getting screen dimensions.

int width

The requested width of the ad.

Returns
@NonNull AdSize

An AdSize object.

getLandscapeInlineAdaptiveBannerAdSize

public static final @NonNull AdSize getLandscapeInlineAdaptiveBannerAdSize(
    @NonNull Context context,
    int width
)

Returns an AdSize with the given width and a height of 0. This ad size allows Google servers to choose an optimal ad size less than or equal to the height of the screen in landscape orientation. The exact size of the ad returned can be retrieved by calling BannerAd.getAdSize inside the AdLoadCallback.onAdLoaded callback. This ad size is most suitable for ads intended to be displayed inside scrollable content.

Parameters
@NonNull Context context

Context to be used for getting screen dimensions.

int width

The requested width of the ad.

Returns
@NonNull AdSize

An AdSize object.

getPortraitAnchoredAdaptiveBannerAdSize

public static final @NonNull AdSize getPortraitAnchoredAdaptiveBannerAdSize(
    @NonNull Context context,
    int width
)

Returns an AdSize with the given width and a Google-optimized height to create a banner ad. The size returned will have an aspect ratio similar to BANNER, suitable for anchoring near the top or bottom of your app. The height will never be larger than 15% of the device's portrait height and never smaller than 50px. This function always returns the same height for any width / device combination.

Parameters
@NonNull Context context

Context to be used for getting screen dimensions.

int width

The requested width of the ad.

Returns
@NonNull AdSize

An AdSize object.

getPortraitInlineAdaptiveBannerAdSize

public static final @NonNull AdSize getPortraitInlineAdaptiveBannerAdSize(
    @NonNull Context context,
    int width
)

Returns an AdSize with the given width and a height of 0. This ad size allows Google servers to choose an optimal ad size less than or equal to the height of the screen in portrait orientation. The exact size of the ad returned can be retrieved by calling BannerAd.getAdSize inside the AdLoadCallback.onAdLoaded callback. This ad size is most suitable for ads intended to be displayed inside scrollable content.

Parameters
@NonNull Context context

Context to be used for getting screen dimensions.

int width

The requested width of the ad.

Returns
@NonNull AdSize

An AdSize object.

getWidth

public final int getWidth()

getWidthInPixels

public final int getWidthInPixels(@NonNull Context context)

Returns the width of this AdSize in physical pixels. For fluid size, it returns -1.

hashCode

public int hashCode()

isAnchoredAdaptiveBanner

public final boolean isAnchoredAdaptiveBanner()

isFluid

public final boolean isFluid()

Returns whether this AdSize is of fluid size or not.

isInlineAdaptiveBanner

public final boolean isInlineAdaptiveBanner()

toString

public @NonNull String toString()