viewpager无限循环
来源:互联网 发布:查看软件注册表 编辑:程序博客网 时间:2024/04/28 04:46
One possibility is setting up the screens like this:
C' A B C A'
C' looks just like C, but when you scroll to there, it switches you to the real C. A' looks just like A, but when you scroll to there, it switches you to the real A.
I would do this by implementing onPageScrollStateChanged like so:
@Overridepublic void onPageScrollStateChanged (int state) { if (state == ViewPager.SCROLL_STATE_IDLE) { int curr = viewPager.getCurrentItem(); int lastReal = viewPager.getAdapter().getCount() - 2; if (curr == 0) { viewPager.setCurrentItem(lastReal, false); } else if (curr > lastReal) { viewPager.setCurrentItem(1, false); } }}
Note that this calls the alternate form of setCurrentItem and passes false
to cause the jump to happen instantly rather than as a smooth scroll.
There are two main drawbacks I see to this. Firstly, upon reaching either end the user has to let the scrolling settle before they can go further. Secondly, it means having a second copy of all of the views in your first and last page. Depending on how resource-heavy your screens are, that may rule out this technique as a possible solution.
Note also that since the view pager doesn't let clicks go through to underlying controls until after the scrolling has settled, it's probably fine to not set up clicklisteners and the like for the A' and C' fragments.
Edit: Having now implemented this myself, there's another pretty major drawback. When it switches from A' to A or C' to C, the screen flickers for a moment, at least on my current test device.
- viewpager无限循环
- 无限循环的ViewPager
- viewpager无限循环
- ViewPager无限循环
- ViewPager无限循环
- Android无限循环ViewPager
- ViewPager无限循环
- ViewPager实现无限循环
- ViewPager无限循环
- ViewPager实现无限循环
- [Android]无限循环ViewPager
- 无限循环的Viewpager
- viewpager无限循环
- 实现无限循环ViewPager
- ViewPager 无限循环
- ViewPager 无限循环。
- viewpager的无限循环方法
- 打造无限自动循环viewpager
- 九度教程--------22
- 解决Xcode项目出现My mac 64-bit/设置允许用户外部资源同步到App/解决CodeSign error: Certificate identity ‘iPhone Distributio
- SQL语句大全
- 在linux下使用c++线程池threadpool
- RMAN - 备份与恢复实践
- viewpager无限循环
- Java学习札记
- 一个小型的操作系统
- live555源码分析----H264的数据处理
- 项目选择 产品分析 效益分析 工具辨析
- threadpool
- 在特定数组中查找最小整数(生成id的o(n)方法)
- 虚拟机VMware的“Cannot connect virtual device floppy0”解决方法
- Linux进程地址空间的一步步探究