0

水平スクロールビュー内でビューをループさせたいのですが。

例:

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 . . . 

私はそれを達成するための良い方法を探しています!

4

2 に答える 2

1

これは、 では実用的ではない可能性がありHorizontalScrollViewます。適切に作成されたPagerAdapterもの ( に対して非常に高い値をgetCount()返し、同じ N 個のビューを返すもの) は、 でこれをやってのけることができるかもしれませんViewPagerPagerAdapterビューのリサイクルが違反するアダプターの動作についていくつかの仮定を行う可能性があるため、組み込みのフラグメントベースの実装のいずれも使用しません。

于 2012-09-04T13:46:57.860 に答える
0

質問が古くても、答えに値します:)

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);
}

それは連続ループを作ります。

于 2015-01-20T16:04:02.553 に答える