Custom Android Views: Carousel RecyclerView

Supah Software
6 min readFeb 19, 2019

I would like to start off by saying that this is my first blog post ever, so please feel free to let me know your criticisms and suggestions.

You can view the all of the source code for this here:
https://github.com/SupahSoftware/AndroidExampleCarousel

In this article, we will go through how to create the following recycler view animation

Here are the libraries you will need in your app level build.gradle file

build.gradle

dependencies {
...
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
}

Next we’re going to start building up our custom RecyclerView code. Let’s create a new class and call it HorizontalCarouselRecyclerView.kt

HorizontalCarouselRecyclerView.kt

class HorizontalCarouselRecyclerView(
context: Context,
attrs: AttributeSet
) : RecyclerView(context, attrs) {
// TODO
}

This is where almost all of our code will live. Let’s create a function that allows us to initialize our RecyclerView with everything that we need.

fun <T : ViewHolder> initialize(newAdapter: Adapter<T>) {
layoutManager =…

--

--