Is there anyway to determine the exact number of pixels that a user has overscrolled
by in an Android ListView? When the user tries to scroll up past the first list item, and the overscroll/bounce animation kicks in, I need to detect the overscroll distance. Basically I'm going to do something in that space, like a fold in animation, similar to the Clear app on iPhone.
I've tried calling getScrollY()
and getTop()
on my ListView, and its items (using getChildAt(0).getTop
), but everything returns 0. For reference my list items are all the same height.
I've also tried adding an onScrollListener
to the listview
and just calculating the difference between the original Y pos on ACTION_DOWN
, and the Y pos on ACTION_MOVE
, but it seems that the listview
scrolls at a slower velocity.
Any help would be great.
What about overriding this method?
protected boolean overScrollBy (int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent)
The scrollY will stay 0, but you could accumulate deltaY when isTouchEvent is true to get how far the user overscrolled.
After much digging, and even more frustration, the answer seems to be that you can't. What's even more annoying is that I took a look at the Android source code and can see that the code I need is all nicely hidden away in the AbsListView's inner gubbings. But all is not lost. Seems that you can build your own view using the AbsListView as a guide, and do what you need inside it. It's more longwinded than I wanted, but so be it. I also found a nice tutorial on how to build your own view, in which you can do whatever you want.
Edit
I finally have a demo up and running on Github. If you're interested you can find it here. When you pull down from the top a new view will rotate in, if you let go or scroll up the view will rotate out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With