ViewPager Tutorial: Getting Started in Kotlin

In this ViewPager tutorial for Android, you’ll learn how to use a ViewPager to navigate between content pages in Kotlin. By Diana Pislaru.

Leave a rating/review
Save for later
Share
You are currently viewing page 3 of 3 of this article. Click here to view the first page.

Where to Go From Here?

You can download the final project for this tutorial here.

Nice job! You’ve modified an app and gave it a nicer UI with the help of ViewPager. You’ve also added a pretty cool TabLayout and implemented the endless scroll. In addition, you learned about the PagerAdapter and had to choose which of the FragmentPagerAdapter and FragmentStatePagerAdapter is best for you application. 

If you want to read more about the ViewPager have a look at the documentation. You can try and customize the transition animation with the help of PageTransformer. Check out this tutorial for that.

Bonus challenge: You can implement dot indicators for your pages as seen in many onboarding flows. Here you can find a nice way of creating dot indicators. Note that this solution won’t work with your final ViewPager from this tutorial as it needs PagerAdapter‘s getCount() method to return the exact number of pages. You can try implementing the indicators instead of the endless scroll. This time try using the default TabLayout instead of the third party library. You can download the solution here.

Feel free to join the forum discussion below if you have any comments or questions! :]

Diana Pislaru

Contributors

Diana Pislaru

Author

Jason Donmoyer

Tech Editor

Odie Edo-Osagie

Final Pass Editor

Joe Howard

Team Lead

Over 300 content creators. Join our team.