ViewPager作为一个循环队列/包装 [英] ViewPager as a circular queue / wrapping
问题描述
我使用的是 ViewPager
与 FragmentStatePagerAdapter
来让一些片段之间的导航。
I am using a ViewPager
with the FragmentStatePagerAdapter
to allow navigation between some fragments.
让我们说我有三个片段: A
, B
和 C
。该ViewPager显示片段A最初,并允许您通过再次刷卡从右到左,然后到C片段刷卡导航到片段B。这使得下面的导航路径: A< - > B< - > ç
。
Let's say I have three fragments: A
, B
and C
. The ViewPager shows Fragment A initially, and allows you to navigate to Fragment B by swiping from right-to-left, and then to Fragment C by swiping again. This allows the following navigation paths: A <--> B <--> C
.
我想是能够由左到右的片段A和有ViewPager显示C片段刷卡,即它表现为一个循环队列,并允许 ... - &GT; C&LT; - &GT; A&LT; - &GT; B&LT; - &GT; C&LT; - &GT; A&LT; - ...
What I would like is to be able to swipe from left-to-right on Fragment A and have the ViewPager show Fragment C, i.e. for it to behave as a circular queue and allow ... --> C <--> A <--> B <--> C <--> A <-- ...
我不想重复在其他位置(即结束了三个以上的情况下)。
I do not want the Fragments duplicated in other positions (i.e. ending up with more than three instances).
这是包装的功能可能有ViewPager?
Is this wrapping functionality possible with a ViewPager?
推荐答案
我已经实现了一个ViewPager / PagerAdapter,可以让伪无限分页行为。它的工作原理,通过指定一个非常大的数作为实际计数,而是将它们映射到数据集/ pageset的实际范围。它弥补一开始就受到了大批也让您可以立即从第一页面滚动到左边。
I've implemented a ViewPager/PagerAdapter that can allow for pseudo-infinite paging behaviour. It works by specifying a very large number as the actual count, but maps them to the actual range of the dataset/pageset. It offsets the beginning by a large number also so that you can immediately scroll to the left from the 'first' page.
它不工作这么好,一旦你到了100万件页(滚动时,你会看到图形毛刺),但是这通常不是一个真实的用例。我可以解决这个问题在一段时间重新计数为一个较低的数字一次,但我会离开它是怎么回事,现在。
It doesn't work so well once you get to 1,000,000th page (you will see graphical glitches when scrolling), but this is typically not a real-world use-case. I could fix this by resetting the count to a lower number once in a while, but I will leave it how it is for now.
在 InfinitePagerAdapter
包装了一个现有ViewPager,所以使用是相当透明的。该 InfiniteViewPager
也做了一些工作,以确保您可能会滚动到左侧和右侧很多次了。
The InfinitePagerAdapter
wraps an existing ViewPager, and so the usage is quite transparent. The InfiniteViewPager
does does a bit of work to make sure you can potentially scroll to the left and right many times.
<一个href="https://github.com/antonyt/InfiniteViewPager">https://github.com/antonyt/InfiniteViewPager
这篇关于ViewPager作为一个循环队列/包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!