Kotlin Image Slider Slideshow Viewpager Example Programmatically

Android Kotlin Image Slider tutorial with example is the main task of our right now.

We will use circular dot navigation indicator to tell user which slide number is currently going on.

This tutorial also includes the automatic slide show with custom time line between each slide.

We need to use the Viewpager to develop this tutorial programmatically.

If you want to develop this example with Java language, then visit automatic image slider android tutorial.

Download the source code for kotlin image slider

[sociallocker]Download Kotlin Android Image Slider Code[/sociallocker]

Step 1. Add dependency

We will use One github library in this tutorial.

Add following lines into your build.gradle(Module:app) file

Step 2. Add Images

Add some images to show into the slider.

Download images by clicking the below link.

[sociallocker]Download images to add into slider[/sociallocker]

You need to add this images into the drawable folder of android studio project.

You can see the drawable directory path in below image.

image slider slideshow viewpager android, kotlin image slider

Step 3. Model Class

Now, we require model class in this example.

Create a new kotlin class named ImageModel.kt and then add below source code in it.

Step 4. Single slide layout

Make one new layout resource file named slidingimages_layout.xml and add following code

Step 5. Adapter Class

Adapter class will provide data to the viewpager.

Prepare a new class named SlidingImage_Adapter.kt

Copy and paste following source code into it

Step 6. Update Main Activity

Replace your existing code of activity_main.xml with below one

Now whole code for MainActivity.kt is something like below

Step 7. Stop Auto Slide

Sometimes you may have to stop the auto sliding feature.

For this purpose, consider following code

If you want stop auto slide then comment out the above code.

We have used Timer class to specify a time interval for each auto sliding.

You can also swipe manually when auto sliding is enabled.

Here sliding interval time is set as 3 seconds. You can change it by updating below

when you updated the values 3000,3000, as a result time interval will be changed.

Output

The end for kotlin image slider android tutorial.

Keep sharing our tutorial and keep coding!

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *