TOP > CarouselAds
Carousel ads are horizontal banner ads that allow app users to scroll horizontally.
Ads can be displayed in the carousel ad frame as many as the specified ad space ID (AdSpotID).
Based on the size specified in the ad space setting on the dashboard, it is drawn according to the resolution of the device.
Runa recommends that you keep the size of the ads displayed in the carousel frame consistent.
- Supported version : v1.6.0+
Use the CarouselAdView
class to implement carousel ads.
In the display of this advertisement, the included ad space is displayed left-aligned and cannot be displayed right-aligned.
There are two ways to place it on the Activity or Fragment to be displayed, defining it in the layout XML file or defining it directly in the program.
Definition by XML
res/layout/main_activity.xml
...
<com.rakuten.android.ads.runa.CarouselAdView
android:id="@+id/carouselAds"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:adSpotIds="@array/adSpotIds"
/>
...
res/values/arrays.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="adSpotIds">
<item>{AD_SPOT_ID1}</item>
<item>{AD_SPOT_ID2}</item>
<item>{AD_SPOT_ID3}</item>
</string-array>
</resources>
MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
findViewById<CarouselAdView>(R.id.carouselAds).show()
}
Programmatically Definition
MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
val yourView = findViewById<ViewGroup>(R.id.anyParentView)
val carouselAdView = CarouselAdView(this).apply {
addAdSpotId("{AD_SPOT_ID1}", "{AD_SPOT_ID2}", "{AD_SPOT_ID3}")
}
yourView.addView(
carouselAdView,
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
)
}
Use CarouselAdStateListener
class to detect ad events and customize app behavior.
By setting the defined CarouselAdStateListener in the CarouselAdView$setCarouselAdStateListener()
method, you will be able to handle the event.
val carouselAdView = CarouselAdView(this).apply {
carouselAdStateListener = object: CarouselAdStateListener() {
override fun onAllLoadsFinished() {}
override fun onLoadSuccess(view: View? = null) {
// Checking Example
val adSpotId = (view as? AdView)?.adSpotId
}
override fun onLoadFailure(view: View? = null, errorState: ErrorState) {
// Checking Example
val adSpotId = (view as? AdView)?.adSpotId
}
override fun onClick(view: View? = null, errorState: ErrorState?) {
// Checking Example
val adSpotId = (view as? AdView)?.adSpotId
}
override fun onLeftApplication() {}
override fun onAdClosed() {}
override fun onWebViewCrashed(adView: AdView?) {}
}
}
method | details |
---|---|
onLoadSuccess(View) | Called every time loading is successful for each ad spot ID set in CarouselAdView |
onLoadFailure(View, ErrorState) | Called each time an ad request fails for each ad spot ID set in CarouselAdView. |
onClick(View, ErrorState) | Called when an ad is clicked. |
onLeftApplication() | Called when an ad is clicked and leaves the application. |
onAdCloseed() | Called Return to app after clicking ad and navigating to destination. |
onAllLoadsFinished() | Called when all loading of the ad spot ID set in CarouselAdView is completed. In this case, it will be called when the read process is completed regardless of the success or failure of each read result. |
onWebViewCrashed(AdView?) | Called when the process inside WebView in AdView is crashed. |
Displayed image | Parameters | Details |
---|---|---|
・nestedAdsSizeAdSize : DEFAULT ・adsSeparatorWidth : 0 |
-> | |
・nestedAdsSizeAdSize : DEFAULT ・offsetStartWidth : 35 |
-> | |
・nestedAdsSizeAdSize : DEFAULT ・offsetEndWidth : 35 |
-> | |
・nestedAdsSizeAdSize : DEFAULT ・adsSeparatorWidth : 35 |
-> | |
・nestedAdsSizeAdSize : ASPECT_FIT | -> | |
・nestedAdsSizeAdSize : ASPECT_FIT ・offsetStartWidth : 35 |
-> | |
・nestedAdsSizeAdSize : ASPECT_FIT ・offsetEndWidth : 35 |
-> | |
・nestedAdsSizeAdSize : ASPECT_FIT ・adsSeparatorWidth : 35 |
-> |
Displayed image | Parameters | Details |
---|---|---|
・isPagerSnapEnabled : true ・nestedAdsSizeAdSize : DEFAULT |
-> | |
・isPagerSnapEnabled : true ・nestedAdsSizeAdSize : ASPECT_FIT |
-> | |
・isPagerSnapEnabled : true ・nestedAdsSizeAdSize : ASPECT_FIT ・offsetStartWidth : 35 ・offsetEndWidth : 35 |
-> | |
・isPagerSnapEnabled : true ・nestedAdsSizeAdSize : ASPECT_FIT ・overhangWidth : 35 ・adsSeparatorWidth : 10 |
-> |
※ The display of the indicator is possible only when the pager is valid.
Displayed image | Parameters | Details |
---|---|---|
・isPagerSnapEnabled : true ・isIndicatorEnabled : true ・nestedAdsSizeAdSize : DEFAULT |
-> | |
・isPagerSnapEnabled : true ・isIndicatorEnabled : true ・nestedAdsSizeAdSize : ASPECT_FIT |
-> |
LANGUAGE :