我想在HorizontallScrollView中循环视图。
示例:
HorizontalScrollView holding 5 Views
When swiping through the Views the behaivior should be like this:
1 -> 2 -> 3 -> 4 -> 5 -> 1 -> 2 . . .
Or backwards:
1 <- 5 <- 4 <- 3 . . . 我正在寻找一个好的方法来完成这一点!
发布于 2012-09-04 21:46:58
这对于HorizontalScrollView来说不太可能是实际的。一个编写得当的PagerAdapter --为getCount()返回一个非常高的值并返回相同的N个视图--也许能够用ViewPager实现这一点。我不会使用这两种内置的基于片段的PagerAdapter实现,因为这些实现可能会对适配器的行为做出一些假设,而您的视图回收可能会违反这些假设。
发布于 2015-01-21 00:04:03
好吧,即使这个问题很老,它也应该得到一个答案:)
简单地获取scrollViews的宽度或高度,并获得x/y滚动的数量。
HorizontalScrollView scroller;
int scrollerWidth = scroller.getMeasuredWidth();
int scrollX = scroller.getScrollX();
int activeViewCount = 0;
activeViewCount = (activeViewCount > 0) ? activeViewCount - 1 : 0;
scroller.smoothScrollTo(activeViewCount * scrollerWidth, 0);
if (scrollX >= scrollerWidth) {
scroller.scrollTo(0, 0);
}这将形成一个连续的循环。
https://stackoverflow.com/questions/12263893
复制相似问题