水平スクロールビュー内でビューをループさせたいのですが。
例:
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 . . .
私はそれを達成するための良い方法を探しています!
水平スクロールビュー内でビューをループさせたいのですが。
例:
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 . . .
私はそれを達成するための良い方法を探しています!
これは、 では実用的ではない可能性がありHorizontalScrollView
ます。適切に作成されたPagerAdapter
もの ( に対して非常に高い値をgetCount()
返し、同じ N 個のビューを返すもの) は、 でこれをやってのけることができるかもしれませんViewPager
。PagerAdapter
ビューのリサイクルが違反するアダプターの動作についていくつかの仮定を行う可能性があるため、組み込みのフラグメントベースの実装のいずれも使用しません。
質問が古くても、答えに値します:)
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);
}
それは連続ループを作ります。