Android: Why Not use an Image Carousel if you have lots of images to show!

Md. Mahmudul Hasan Shohag
2 min readMar 30, 2020

--

Do you know that creating an image carousel in Android is easier then you think! 😉

Recently in a project, I have to show some images for preview. I am thinking to use an image carousel library to show the images. But the library I found does not make me feel good 😑! They are old or have discontinued/old library dependency 🙄!

So I thought let’s try to make one 😁! Then I checkout the existing libraries source codes and I found that creating a carousel is a two-line code 😲!

Really!

To create a carousel (ViewPager like view) just attach a RecyclerView to a SnapHelper!

That’s it! Try it yourself…

Though you have to create a RecyclerView adapter, design item layout, which consists of ImageView, the ImageView should be fully match_parent in height and width, styling the view, adding indicator, adding navigator, listener……… 😒

For the lazy 😴…

That means to make everything work you have to write more codes. So to save you from that I create an image carousel library, Why Not! Image Carousel!

It’s simple to use and fully customizable.

How to use…

Add repository to the root build.gradle file:

Add dependencies to the module build.gradle file:

Replace X.X.X with the latest version of the library. Check out the latest release version from here.

Finally add the ImageCarousel to your XML layout:

Then add item to the carousel:

That’s all need to create the first carousel view in the following image:

Examples of Why Not! Image Carousel!

Feeling interesting 🤔? Then check out the details usage from the repository. A Sample project also included here, using both Kotlin and Java 😎.

Repository 👉 https://github.com/ImaginativeShohag/Why-Not-Image-Carousel

Sample 👉 https://github.com/ImaginativeShohag/Why-Not-Image-Carousel/tree/master/sample

Like it? then…

Use it… clone it… fork it… give PRs and finally, give a star to the repository and share it if you like…

--

--