androidanimationandroid-viewpager

Disabling animation in ViewPager


I'd like to disable all the animations for the transitions in my custom ViewPager. This view pager contains four tabs -and each tab loads a Fragment- and what the view pager does is to switch the tabs: for example first tab is the index, second is map, etc.

The problem is that if, being the first tab chosen, I click on the fourth tab, I can see how the ViewPager goes through the second and third tab and stops on the fourth, and I don't want that to happen.

I tried to disable all the animations for this ViewPager trying to use a setAnimation to null every time the user chooses a new tab to be displayed, but it still doesn't work.

Any idea to achieve this, please? Thanks a lot in advance!

EDIT: I also tried to override onCreateAnimation for each Fragment but still not working


Solution

  • I finally found out: the issue can be solved by just calling the mViewPager.setCurrentItem(position) with an extra parameter to false, which is the smooth scroll for the ViewPager. After this, the scroll will be done without any smoothing and thus the animations won't be seen.