Banner
Última actualización
Última actualización
Banner ads are rectangular image or text ads that occupy a space inside the application layout. They stay on screen while the users interact with the app and can automatically refresh after a certain period of time. If you are new in mobile advertising, they are an excellent choice to start.
There are two ways to integrate a banner: using code or adding the banner view inside a layout. Below we show some examples for both methods:
The widget has support for the following parameters:
The BannerAd
class providers the following methods to configure the instance:
Adaptive banners are a new banner format where the size of the ads is adapted according to the device and the app user-interface, in order to maximize performance.
Currently there is support for two kind of adaptive banners:
This kind of banner is designed to replace the traditional 320x50 banners and be positioned at the top or bottom of the screen.
To make use of this format, the following code must be used to configure an adaptive size:
Alternatively, this other option can be implemented to let the SDK calculate the banner width, where the BannerAd
instance itself or the View
that will contain it should be passed:
In this option, it is highly recommended that the View
passed to the method is already added to the app’s layout, so that the SDK can correctly calculate all the dimensions.
This other kind of banner, in comparison to the anchored, is designed to have a variable height and be positioned inside a scrolling content.
In this case, the following code must be used to configure a proper adaptive size:
Alternatively, this other option can be implemented to let the SDK calculate the banner width, where the BannerAd
instance itself or the View
that will contain it should be passed:
In this option, it is highly recommended that the View
passed to the method is already added to the app’s layout, so that the SDK can correctly calculate all the dimensions.
A listener can be set to any BannerAd
instance to receive the events that happen during its lifecycle. For this, it is needed to implement the BannerAd.Listener
interface as shown in the example below:
Parameter
Type
Required
Description
app:adUnitId
String
Yes
The ad unit ID to assign to the banner
app:adSize
AdSize
No
Maximum size (height) for the banner. The possible values for this parameter are declared in the AdSize
class
app:autoRefreshTime
Integer
No
Value in seconds that represents the time that must elapse to load a new banner ad
Method
Required
Descripción
setAdUnitId(String)
Yes
Assigns an ad unit to the banner
setAdSize(AdSize)
No
Maximum size (height) for the banner. The possible values for this parameter are declared in the AdSize
class
setAutoRefreshTime(long)
No
Value in milliseconds that represents the time that must elapse to load a new banner ad
setAutoRefreshTime(long, TimeUnit)
No
Same as previous method, but allows to specify the time unit of the passed value