在ViewPager中禁用动画 [英] Disabling animation in ViewPager
问题描述
我想在自定义 ViewPager
中禁用所有动画,以进行过渡。
此视图分页器包含四个选项卡-每个选项卡均加载 Fragment
-,并且该视图分页器的作用是切换选项卡:例如,第一个选项卡是索引,第二个是地图,等等。
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.
问题是,如果作为第一个选择的标签,我单击了第四个标签,我可以看到 ViewPager
经过第二个和第三个选项卡,然后在第四个选项卡上停止,我不希望这种情况发生。
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.
我尝试过禁用此 ViewPager
的所有动画,尝试将 setAnimation
用作 null
每次用户选择要显示的新标签,但仍然无法正常工作。
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!
编辑:我还尝试为每个<$覆盖 onCreateAnimation
c $ c> Fragment 但仍然无法工作
I also tried to override onCreateAnimation
for each Fragment
but still not working
推荐答案
我终于发现:问题可能是只需调用 mViewPager.setCurrentItem(position)
并使用 false
的额外参数即可解决,这是平滑滚动的方法 ViewPager
。
此后,滚动将完成而不会进行任何平滑处理,因此将看不到动画。
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.
这篇关于在ViewPager中禁用动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!