Requisitos previos
-
Using RecyclerView
We need you to edit your item Layout, so it has a wrapper/holder for the Ads. Keep in mind this wrapper/holder could be expanded or contracted, so make sure your layout adapts to this changes look into adaptive layouts for this, this size changes in the layout will be limited by the ad configurations that the infinite scroll is using, these can be edited in the code on manual initialization, or in our dashboard in case of auto and single tag initialization.
This is because we can not edit your data for adding new items to the adapter, so we take the existing item views and add the ads to them. You can customize which items have ads when you create the configuration for the infinite scroll.
Get the RecyclerView
// Find your view, this is the simplest but there are better ways
val rv = findViewById<RecyclerView>(R.id.infiniteScroll_recyclerView_manual)
// Create and use your own adapter
rv.adapter = <add your adapter>
// Linear layout is the most common but feel free to swap it
rv.layoutManager = LinearLayoutManager(this)
Prepare the Item View
Normal item Code would look something like
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp">
<Button
android:id="@+id/infinitescroll_item_button_auto"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
For adding the wrapper to this item we would do something like
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp">
<Button
android:id="@+id/infinitescroll_item_button_auto"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="infiniteScroll_ad_wrapper_tag"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/infinitescroll_item_button_auto"
app:layout_constraintVertical_bias="0.0">
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Mostrar el anuncio
En el ejemplo estamos utilizando un Test Id.
Si no estás probando la aplicación, cámbiala por el ID apropiado que te dimos.
# MainActivity.kt
val infiniteScrollConfigId = ConfigBuilder.INFINITE_SCROLL_TEST_R89_CONFIG_ID
val itemAdWrapperTag = <Defined ad wrapper tag for each item view that's going to be in the recycler view>
RefineryAdFactory.createInfiniteScroll(infiniteScrollConfigId, rv, itemAdWrapperTag)
Eventos del ciclo de vida
Puedes suscribirte a estos eventos con el mismo método pero pasando un nuevo objeto como parámetro. Los detalles sobre este objeto se encuentran en la Referencia.
# MainActivity.kt
val infiniteScrollConfigId = ConfigBuilder.BANNER_TEST_R89_CONFIG_ID
val infiniteScrollLifecycleListener = <create the listener with a method or inline>
RefineryAdFactory.createInfiniteScroll(infiniteScrollConfigId, rv, infiniteScrollLifecycleListener)