Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 531
noloman Avatar asked Feb 04 '13 10:02

noloman


People also ask

How to disable animation of ViewPager?

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.

How do I stop ViewPager from scrolling?

A simple solution is to create your own subclass of ViewPager that has a private boolean flag, isPagingEnabled . Then override the onTouchEvent and onInterceptTouchEvent methods. If isPagingEnabled equals true invoke the super method, otherwise return .


1 Answers

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.

like image 113
noloman Avatar answered Sep 28 '22 03:09

noloman