How to create ViewPager with Swipe Animation in Android using android studio

0 811

ViewPager with Swipe Animation in Android

Hello guys, today we will learn to add ViewPager with Swipe Animation in Android. Android provides many UI controls to create fascinating UI screens for Apps. One interesting feature is to slide between different screens. Android offers a UI control for creating sliding screens using ViewPager. ViewPager can animate screen slides automatically. Swipe Animation is used with it to swipe screens from left to right and vice versa.

Let’s see the steps to add ViewPager with swipe Animation in Android.

Steps to Follow

  1. Create a new Project in Android Studio and name it.
  2. Select the minimum API level as 16 and Android version above or equal to Jellybean 4.1.
  3. Select Blank Activity and click Next.
  4. Name your Blank Activity as MainActivity and press Finish.
  5. Click on MainActivity.java and write the following code in it.

6. Inside package  create new class named, CustomPagerAdapter.java. Write the following code inside it.

7. Go to layout activity_main.xml under the res > layout folder. Write the following code inside activity_main.xml.

8. Right click on res > New > Layout resource file. Enter the File name as view_deep_orange.xml and press ok.

9. Write the following code inside view_deep_orange.xml.

10. Again Right click on res > New > Layout resource file. Enter the File name as view_orange.xml and press ok.

11. Follow the same steps, click on res > New > Layout resource file. Enter the File name as view_pink.xml and press ok.

12. Inside package create new class and name it as  ModelObject.java and write the following code inside it:

13. Select res>values>colors.xml. Write the following code inside colors.xml.

14. Now you can run and test your code and you would get the output.

Download Source code

Comments

comments

Leave A Reply

Your email address will not be published.