Skip to main content

Image Slider in Android with library [Easy and Fast Implementation]

How to make Image Slider in Android App

how to make image slider in android
How to make image slider in android
Today, I am going to show you how you can make a decent image slider in your android app very easily without writing lots of code.

check this gif below for end result what we will be going to make.

image slider in android

is it look beautiful? To make this type of image slider or image carousel. Follow these simple step which is given below.

First, of course, you have to create a new project in android studio.

Choose an empty activity and then choose the app name and hit the finish button.

Wait for some time to build your project and after the build.

Move your images to your drawable folder.

android drawable folder

here as you can see, I have move 3 images name img1, img2 and img3.

After this, now we have to add our dependency for image slider.

Add this dependency in your build.gradle(app) file


After adding the dependency hit the sync now button (top right corner).

gradle sync button
Now go to the activity xml file.

Remove Textview from the xml file and also remove ConstraintLayout and add LinearLayout

Your file will look like this below.

android activity xml


Now it's time to add code for Image Slider.

Copy below code and paste it in LinearLayout.

You can experiment with the attributes of Image Slider and go with which suits your requirements.

Your xml file now looks like this.

android activity xml image slider


Now it's time to set Images to the Image Slider.

Go to your java activity file e.g MainActivity.java

Now add this code in your onCreate method.



Code Explanation:

first, we are getting the carousel view from xml by using the findViewById method.

then we store the reference of images in an integer array.

After that, we set how many image sliders will be there by specifying the image array length.

in the next line, we set the image listener which accept an interface and in the listener, we are getting the position of each slide

By using this position we are setting our image resource from array of images.

Now your whole file should look like this.

android activity java image slider

Now hit the run button and run your app in your device

Voila! Your nice beautiful image slider is ready to rock.

Customize your Image slide as per your need and make a beautiful mobile app.

So This comes to the end of a great tutorial. If you like this tutorial share it with your friends and mates. Thank You.

Popular Posts

Customize rating bar in android

Working with Bottom Navigation bar in Android [Full Guide]

Custom Switch in Android | Akshayrana.in | Android Tutorial