Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions loopview/src/main/java/com/weigan/loopview/LoopView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down