Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ViewPager With different Animation like zoom in,fade etc

Tags:

People also ask

What is difference between ViewPager and ViewPager2?

ViewPager2 is an improved version of the ViewPager library that offers enhanced functionality and addresses common difficulties when using ViewPager . ViewPager2 has several advantages such as vertical orientation support, RTL and access to DiffUtil .

Is ViewPager deprecated?

This method may be called by the ViewPager to obtain a title string to describe the specified page. This method is deprecated. This method should be called by the application if the data backing this adapter has changed and associated views should update.

What is ViewPager2 Android studio?

ViewPager2 uses FragmentStateAdapter objects as a supply for new pages to display, so the FragmentStateAdapter will use the fragment class that you created earlier. Create an activity that does the following things: Sets the content view to be the layout with the ViewPager2 .


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.