[Tutorial] ViewPagerTransforms - Animations for transforming ViewPager on Android Studio
In this post, I’ll show you how to use ViewPagerTransforms Library to add some beautiful animations for transforming ViewPager on your Androids apps.
I - About Android Tutorials
I’ll be creating a big number of Android tutorials, showing you how to use nice libraries, UI, tips, and more.
I’ll be using Android Studio and Gradle in all tutorials.
If you need some help with any Android lib or feature, feel free to comment here and if possible, I can write a new tutorial about it :)
Library containing common animations needed for transforming ViewPager scrolling on Android v13+.
This library is a rewrite of the JazzyViewPager library and owes credit of the animation concepts directly to its source.
The purpose of this rewrite is to provide an easier to use and extend implementation of ViewPager animations.
This library is really simple to use. You’ll be able to add nice animations to the default android ViewPager.
III - Creating a new project
Now, let’s start to work with it. Start a new Android Studio project. And make sure to be using Android v13+ to be able to use this library. C
Create your app with a Blank Activity, called MainActivity.
Now, to add ViewPagerTransforms as a Gradle dependency, click on app, and with the right click of mouse, go to Open Module Settings(F4)
Open the Dependencies tab, click on the plus button and Library Dependency. Now add the following line to the search input and get the last version of this lib.
Click Ok and wait the Gradle Sync to finish. Now, just to make sure that your app is working, click in the run button.
IV - Layout files
Now, let’s edit our layout files. The first step is to create a layout to each slide. To make this tutorial simple, we are going to use the same layout file to all slides.
Create a simple xml file inside layout folder with the name slide_page.xml:
Now, just add a ViewPager to your activity_main:
V - Coding it
Now, it’s time to code our application :)
Open you MainActivity.java and remove some codes, keep it simple, like this one:
Add some variables to work with the Android ViewPager:
Now, add the following code on OnCreate method:
You can see a list with all available animation here: https://github.com/ToxicBakery/ViewPagerTransforms/tree/master/library/src/main/java/com/ToxicBakery/viewpager/transforms
Add the following method to handle back button click:
To get a page_slide.xml and show it, it’s necessary to handle it with a Fragment. So, inside your main MainActivity class, the this new class:
Create a new public class, SlideFragment.java. This class will handle each new page and show it.
Now, you can run and test your app :)
Feel free to test all animations and choose the best one to your app. You just need to edit the following line:
That’s it, thanks for reading!