12

I have created ViewPager ,there are only 2 page are there,I want to put animation like fade in,scale,zoom,3d etc when pager scroll one page to another second one,means second entire page display with specific animation , I have no idea to how to do this,please any one give me a some example of put animation when move to another page that time we animate pager.

Mainly I have three class for pager :1) ViewPagerMainActivity : it call two fragment that is swipe in this main look like enter code here

   public class ViewPagerMainActivity extends FragmentActivity implements
    OnClickListener, OnPageChangeListener {

@Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_pager_main);
                                     <other code here>
     }

private class MyPagerAdapter extends FragmentPagerAdapter {

    public MyPagerAdapter(
            android.support.v4.app.FragmentManager fragmentManager) {
        super(fragmentManager);
    }

    @Override
    public Fragment getItem(int pos) {
        switch (pos) {

        case 0:
            return FirstFragment.newInstance("");

        case 1:
            return SecondFragment.newInstance("");

        default:
            return SecondFragment.newInstance("Default");
        }
    }

    @Override
    public int getCount() {
        return 2; // return no of fragment created by us
    }
}

}

In first fragment containing swipe design and second fragment contains second xml file design when I swipe first fragment to another at that time I want to put animation. means while swiping it display any one animation effect choose from different animation option. how to I create animation and where to put this in it. please help quickly thanks in advance.

Aditi Parikh
  • 1,522
  • 3
  • 13
  • 34
Nirav Mehta
  • 1,715
  • 4
  • 23
  • 42
  • 1
    Is this what you are looking for: http://developer.android.com/training/animation/screen-slide.html – Chintan Soni Apr 17 '14 at 09:53
  • Check out those three movie screens, and choose whichever animations you would like to implement. – Chintan Soni Apr 17 '14 at 09:56
  • i try this it give error in implementing view pager like create interface view pager in : public class ZoomOutPageTransformer implements ViewPager.PageTransformer – Nirav Mehta Apr 17 '14 at 10:07
  • Can you please post your activity code ? – Chintan Soni Apr 17 '14 at 10:19
  • i just copy ZoomOutPageTransformer class from your link and error is in first line of defining class, viewPager can not be resolve to type.while ` public class ZoomOutPageTransformer implements ViewPager.PageTransformer` <-- error here `viewPager can not be resolve to type` { all link code } – Nirav Mehta Apr 17 '14 at 10:25
  • Actually i developing a screen lock i over all but i want to add animation in my apps first page is for swipe and then second page is to enter number password , when i swipe to another password page at that time i want to user specific animation – Nirav Mehta Apr 17 '14 at 10:30
  • Please anyone answere me – Nirav Mehta Apr 17 '14 at 11:49

1 Answers1

38

You can attach PagerTransformer to ViewPager :

         mViewPager.setPageTransformer(false, new ViewPager.PageTransformer() {
         @Override
         public void transformPage(View page, float position) {
                 // do transformation here
          }
         });

You can go through following links which will help you :

http://developer.android.com/training/animation/screen-slide.html#pagetransformer or http://andraskindler.com/blog/2013/create-viewpager-transitions-a-pagertransformer-example/

Andras K
  • 932
  • 9
  • 15