AdSize

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

const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int

Public companion functions

AdSize

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

AdSize

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

AdSize
getInlineAdaptiveBannerAdSize(width: Int, maxHeight: Int)

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

AdSize

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

AdSize

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

AdSize

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

AdSize

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

Public companion properties

AdSize

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

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.

AdSize

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

AdSize

An invalid AdSize that will cause the ad request to fail immediately.

AdSize

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

AdSize

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

AdSize

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

AdSize

A special variant of FLUID to be set on SearchAdView when loading a DynamicHeightSearchAdRequest.

AdSize

IAB wide skyscraper ad size (160x600 density-independent pixels).

Public constructors

AdSize(width: Int, height: Int)

Creates a new AdSize.

Public functions

open operator Boolean
equals(other: Any?)
Int

Returns the height of this AdSize in physical pixels.

Int

Returns the width of this AdSize in physical pixels.

open Int
Boolean

Returns whether this AdSize is of fluid size or not.

open String

Constants

const val BANNER_HEIGHT = 50: Int
const val BANNER_WIDTH = 320: Int

FULL_BANNER_HEIGHT

const val FULL_BANNER_HEIGHT = 60: Int

FULL_BANNER_WIDTH

const val FULL_BANNER_WIDTH = 468: Int

LARGE_BANNER_HEIGHT

const val LARGE_BANNER_HEIGHT = 100: Int

LARGE_BANNER_WIDTH

const val LARGE_BANNER_WIDTH = 320: Int

LEADERBOARD_HEIGHT

const val LEADERBOARD_HEIGHT = 90: Int

LEADERBOARD_WIDTH

const val LEADERBOARD_WIDTH = 728: Int

MEDIUM_RECTANGLE_HEIGHT

const val MEDIUM_RECTANGLE_HEIGHT = 250: Int

MEDIUM_RECTANGLE_WIDTH

const val MEDIUM_RECTANGLE_WIDTH = 300: Int

WIDE_SKYSCRAPER_HEIGHT

const val WIDE_SKYSCRAPER_HEIGHT = 600: Int

WIDE_SKYSCRAPER_WIDTH

const val WIDE_SKYSCRAPER_WIDTH = 160: Int

Public companion functions

getCurrentOrientationAnchoredAdaptiveBannerAdSize

fun getCurrentOrientationAnchoredAdaptiveBannerAdSize(
    context: Context,
    width: Int
): AdSize

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
context: Context

Context to be used for getting screen dimensions.

width: Int

The requested width of the ad.

Returns
AdSize

An AdSize object.

getCurrentOrientationInlineAdaptiveBannerAdSize

fun getCurrentOrientationInlineAdaptiveBannerAdSize(
    context: Context,
    width: Int
): AdSize

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. This ad size is most suitable for ads intended to be displayed inside scrollable content.

Parameters
context: Context

Context to be used for getting screen dimensions.

width: Int

The requested width of the ad.

Returns
AdSize

An AdSize object.

getInlineAdaptiveBannerAdSize

fun getInlineAdaptiveBannerAdSize(width: Int, maxHeight: Int): AdSize

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. This ad size is most suitable for ads intended to be displayed inside scrollable content.

Parameters
width: Int

The requested width of the ad.

maxHeight: Int

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
AdSize

An AdSize object.

Throws
kotlin.IllegalArgumentException

If maxHeight is not positive.

getLandscapeAnchoredAdaptiveBannerAdSize

fun getLandscapeAnchoredAdaptiveBannerAdSize(context: Context, width: Int): AdSize

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
context: Context

Context to be used for getting screen dimensions.

width: Int

The requested width of the ad.

Returns
AdSize

An AdSize object.

getLandscapeInlineAdaptiveBannerAdSize

fun getLandscapeInlineAdaptiveBannerAdSize(context: Context, width: Int): AdSize

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. This ad size is most suitable for ads intended to be displayed inside scrollable content.

Parameters
context: Context

Context to be used for getting screen dimensions.

width: Int

The requested width of the ad.

Returns
AdSize

An AdSize object.

getPortraitAnchoredAdaptiveBannerAdSize

fun getPortraitAnchoredAdaptiveBannerAdSize(context: Context, width: Int): AdSize

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
context: Context

Context to be used for getting screen dimensions.

width: Int

The requested width of the ad.

Returns
AdSize

An AdSize object.

getPortraitInlineAdaptiveBannerAdSize

fun getPortraitInlineAdaptiveBannerAdSize(context: Context, width: Int): AdSize

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. This ad size is most suitable for ads intended to be displayed inside scrollable content.

Parameters
context: Context

Context to be used for getting screen dimensions.

width: Int

The requested width of the ad.

Returns
AdSize

An AdSize object.

Public companion properties

BANNER

val BANNERAdSize

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

FLUID

val FLUIDAdSize

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

val FULL_BANNERAdSize

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

INVALID

val INVALIDAdSize

An invalid AdSize that will cause the ad request to fail immediately.

LARGE_BANNER

val LARGE_BANNERAdSize

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

LEADERBOARD

val LEADERBOARDAdSize

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

MEDIUM_RECTANGLE

val MEDIUM_RECTANGLEAdSize

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

SEARCH

val SEARCHAdSize

A special variant of FLUID to be set on SearchAdView when loading a DynamicHeightSearchAdRequest.

WIDE_SKYSCRAPER

val WIDE_SKYSCRAPERAdSize

IAB wide skyscraper ad size (160x600 density-independent pixels). This size is currently not supported by the Google Mobile Ads network; this is intended for mediation ad networks only.

Public constructors

AdSize

AdSize(width: Int, height: Int)

Creates a new AdSize.

Parameters
width: Int

The width of the ad in density-independent pixels.

height: Int

The height of the ad in density-independent pixels.

Throws
kotlin.IllegalArgumentException

If the width or height is negative.

Public functions

equals

open operator fun equals(other: Any?): Boolean

getHeightInPixels

fun getHeightInPixels(context: Context): Int

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

getWidthInPixels

fun getWidthInPixels(context: Context): Int

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

hashCode

open fun hashCode(): Int

isFluid

fun isFluid(): Boolean

Returns whether this AdSize is of fluid size or not.

toString

open fun toString(): String

Public properties

formatString

val formatStringString

height

val heightInt

inlineMaxHeight

val inlineMaxHeightInt

isAnchoredAdaptiveBanner

val isAnchoredAdaptiveBannerBoolean

isInlineAdaptiveBanner

val isInlineAdaptiveBannerBoolean

width

val widthInt