I want to keep track of the ScrollY on a Scrollview (no, I can't use a grid or a list)
I am using the ViewTreeObserver with an onScrollChanges Listener to it. However, it gets fired multiple times. Even worse: when it gets called 3 of 4 times, the scrollY of the scrollview is 0 and 1 time I get the correct amount. However, it's not like every 4th call is correct, the moment when the correct value is fired is random, and I need to be able to listen to the scrollposition 0.
Here is the Code I use to observer my Scrollview:
mScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { Log.d("StupidScrollView", "Scroll positionY: " + mScrollView.getScrollY()); } }); Sample output:
D/StupidScrollView﹕ Scroll positionY: 0 D/StupidScrollView﹕ Scroll positionY: 0 D/StupidScrollView﹕ Scroll positionY: 0 D/StupidScrollView﹕ Scroll positionY: 77 I have to mention, I am in a ViewPager and my fragments contain a Scrollview which needs to be observed. It somehow sounds like some issue related to that.