saarraz1 saarraz1 - 7 months ago 127
Android Question

Android getting exact scroll position in ListView

I'd like to get the exact, pixel position of the ListView scroll.
And no, I am not referring to the first visible position.

Is there a way to achieve this?


Okay, I found a workaround, using the following code:

View c = listview.getChildAt(0);
int scrolly = -c.getTop() + listview.getFirstVisiblePosition() * c.getHeight();

The way it works is it takes the actual offset of the first visible list item and calculates how far it is from the top of the view to determine how much we are "scrolled into" the view, so now that we know that we can calculate the rest using the regular getFirstVisiblePosition method.