在 ViewPager 中禁用动画 [英] Disabling animation in ViewPager

查看:36
本文介绍了在 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 的所有动画,每次用户选择一个新选项卡时,尝试使用 setAnimationnull显示,但它仍然不起作用.

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!

我也尝试为每个 Fragment 覆盖 onCreateAnimation 但仍然没有工作

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

推荐答案

我终于发现:这个问题可以通过调用 mViewPager.setCurrentItem(position) 和一个额外的参数来解决 mViewPager.setCurrentItem(position)code>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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆