Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if the list view is about to stop scrolling?

Tags:

android

I need to do some animations in a listview after it is flinged and is about to stop.I have a listview which is going to be of a fixed height(well dont ask me why), and whenever the scroll stops , it should have three elements visible. What i do now is detect when the list reaches SCROLL_STATE_IDLE and if i have two elements visible at that time, i use smoothScrollToPosition and reach a state of 3 items visible and it works fine, but what i would like to do is detect when the scroll is about to stop and stop the scroll programatically when there are three items visible. Is that even possible... Any code snippets, pseudo code, algo would help me.

like image 900
Rasmus Avatar asked Nov 02 '22 00:11

Rasmus


1 Answers

You can set an OnScrollListener, and then store the value from absListView.getScrollY() each sample and compare it the previous sample to compute the velocity of the scroll. Once that drops below a threshold you define, you can take over scrolling.

like image 105
Jens Zalzala Avatar answered Nov 13 '22 15:11

Jens Zalzala