android - 如何实现Fragment左右无限滑动功能?
高洛峰
高洛峰 2017-04-17 17:36:22
0
4
611


上面那张图是智联的,大概就要这样一个效果

昨天想了半天,简单的实现了这个效果github-有图有真相
思路是用一个List保存数量有限的Fragment,adapter的getCount返回Integer.MAX_VALUE
但是感觉往里传值的时候太麻烦了

请问各位有没有合适的方法实现这个效果

https://github.com/qmr777/Rec...
插不了图片了。。。上面是我的实现

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(4)
左手右手慢动作

It would be better if this is not just ViewPager + Fragment的实现么,只不过他要实现无限滑动的功能罢了。传值还是在不同的Fragment中传值,当然能优化成一个Fragment.

阿神

The correct answer upstairs is actually a viewPager. Just write a fragmentStatePagerAdapter and put your list in it. This can control the number of saved fragments and create new fragments.

迷茫

I have done this before, and the implementation method is ViewPager+Fragment. The actual content and some details depend on the application logic.

黄舟

My approach is:

Suppose there are three fragments, namely f1, f2, and f3. Then when I initialize the PagerAdapter of ViewPager, a total of 5 fragments are returned. The order is: f3,f1,f2,f3,f1. The default currentItem is 1, which is f1.
Then customize ViewPager.OnPageChangeListener. In the onPageScrollStateChanged method, when the state is IDLE (stopped), if the current currentItem is 0, use setCurrentItem(4, false). If it is 4, use setCurrentItem(1, false).

I believe that smart students will understand my implementation logic.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template