Android: Making animation ViewPager with JazzyViewPager library

    ViewPager is "official" widget for sliding screens in Android. In this action, we usally would like to make it more smoothly or flexible. In this tutorial, you will learn how to use JazzyViewPager library to make ViewPager with some animations, your application will be better!

1. Download and import library

- Download library project from Github and extract this zip file.
- Import project from "lib" folder after extract, it will become "MainActivity" project in Eclipse.
- Start a new android project and make reference to this library project:

2. Make ViewPager "components"

    Nothing special, we create a ViewPagerAdapter extends FragmentStatePagerAdapter or FragmentPagerAdapter. In this adapter, like the library document said, in order to get the animations to work correctly for more than 3 Views, we'll have to add the following to the instantiateItem() method of our PagerAdapter
Source code for adapter:

Create a simple Fragment for each ViewPager page:
And it's layout:

3. Create Activity to run

    In this activity, we will change ViewPager sliding style based on selecting item in a spinner. Layout (xml) for it:

And programatically code:

4. Runing application

Our result like this:

5. References 

- Official library page in Github: https://github.com/jfeinstein10/JazzyViewPager
- Author Home page: http://jeremyfeinstein.com/

(Sorry for ads)

Share


Previous post
« Prev Post
Next post
Next Post »