saarraz1 saarraz1 - 5 months ago 76
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?

Answer

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.