I'm looking into adding overscrolling (not the color changing) into my project, but even after reading the API docs and several questions on here I still don't really understand what I need to do to get it to work.
According to the API doc for OverScroller: "this class encapsulates scrolling with the ability to overshoot the bounds of a scrolling operation. This class is a drop-in replacement for Scroller in most cases."
I had a Scroller object before in my parent class:
public boolean onTouchEvent(MotionEvent ev) {
....// code to calculate deltas
if (deltaY != 0 || deltaX != 0)
scrollBy(deltaX, deltaY);
}
And I went to change it to this:
if (deltaY != 0 || deltaX != 0)
overScrollBy(deltaX, deltaY, getScrollX(), getScrollY(),
child.getRight() - getWidth(), child.getBottom() - getHeight(),
OVERSCROLL_DISTANCE, OVERSCROLL_DISTANCE, false);
And now scrolling doesn't work at all! fling()
works fine as a drop in replacement but not scroll....
In summary I have two questions:
- Why is scrolling not working with
overScrollBy
? Do I have to add additional code to make this work? - Why do I have to call
mScroller.fling()
and onlyoverScrollBy()
? Why notmScroller.overScrollBy()
? Is it somehow built into theView
class?
This may be potentially be quite obvious, but I'm struggling here. Any help would be most appreciated, thanks!