Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

android - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...