Reputation: 2504
I have set up smoothScrollToPosition
on a listview
and it works perfect! However... I would rather it put the position at the top of the listview
rather than just on the screen (mostly on the bottom if its needed to scroll down). Any ideas how i can accomplish this?
Upvotes: 2
Views: 3330
Reputation: 219
recycleviewlist.post(new Runnable() {
@Override
public void run() {
new CountDownTimer(totalScrollTime, scrollPeriod) {
public void onTick(long millisUntilFinished) {
recycleviewlist.smoothScrollBy( widthToScroll,0);
}
public void onFinish() {
// gridlayoutmanager
// recycleviewlist.scrollToPosition(0);
gridlayoutmanager1
.scrollToPosition(Integer.MAX_VALUE / 2);
}
}.start();
}
});
Upvotes: 0
Reputation: 55370
Use smoothScrollToPositionFromTop()
. It places the item at the specified position a specified number of pixels from the top of the ListView (if possible). You should simply supply a small offset.
Note: requires API level 11+.
Upvotes: 5