I am trying to build my own grid view functions - extending on the GridView
.
The only thing I cannot solve is how to get the current scroll position of the GridView
.
getScrollY()
does always return 0, and the onScrollListener
's parameters are just a range of visible child views, not the actual scroll position.
This does not seem very difficult, but I just can't find a solution in the web.
Anybody here who have an idea?
On Gingerbread, GridView getScrollY() works in some situations, and in some doesn't. Here is an alternative based on the first answer. The row height and the number of columns have to be known (and all rows must have equal height):
The first answer also gives a good clue on how to pixel-scroll a GridView. Here is a generalized solution, which will scroll a GridView equivalent to scrollTo(0, scrollY):
The functions are implemented inside a subclassed GridView, but they can be easily recoded as external.
I did not find any good solution, but this one is at least able to maintain the scroll position kind of pixel-perfectly:
By that you can not get an absolute scroll position, but a visible item + displacement pair.
NOTES:
Hope that helps and gives you an idea.