diff --git a/loopview/src/main/java/com/weigan/loopview/LoopView.java b/loopview/src/main/java/com/weigan/loopview/LoopView.java index d617a5e..20895ea 100644 --- a/loopview/src/main/java/com/weigan/loopview/LoopView.java +++ b/loopview/src/main/java/com/weigan/loopview/LoopView.java @@ -368,6 +368,32 @@ public void setCurrentPosition(int position) { } } + + /** + * scroll to designated item + * + * @param i + */ + public void smoothScrollToItem(int i) { + if (items == null || items.isEmpty()) { + return; + } + if (i < 0) { + i = 0; + } + if (i > items.size() - 1) { + i = items.size() - 1; + } + cancelFuture(); + float itemHeight = lineSpacingMultiplier * maxTextHeight; + int i1 = i - getSelectedItem(); + if (i1 == 0) + return; + mFuture = mExecutor.scheduleWithFixedDelay(new SmoothScrollTimerTask(this, (int) (itemHeight * i1)), 0, 15, TimeUnit.MILLISECONDS); + invalidate(); + } + + @Override protected void onDraw(Canvas canvas) { if (items == null) {