To answer your questions from the prompt:
- There are no APIs to get the current velocity of ScrollView.
- You can stop the current fling by careful handling of touch events as described in a previous SO post.
Looking at the ScrollView source code, it uses an OverScroller to handle the fling events. There are two ways of approaching this:
- Use reflection to access the mScroller private field within ScrollView. Once you have accessed it you can get the current velocity through its public API:
public float getCurrVelocity();
Using reflection is never ideal since you have to worry about it breaking across android versions, but a simple isolated usage can be relatively efficient.
- Override the fling() method in ScrollView and instantiate a OverScroller to keep track of the scrolling. If all goes well, your Overscoller will always be in the same state as the one within ScrollView.
Something like this:
@Override
public void fling(int velocityY)
{
// Pass through fling to parent
super.fling(velocityY);
// Keep track of velocity using our own Overscoller instance
mOurOverscroller = mScroller.fling(mScrollX, mScrollY, 0, velocityY, 0, 0, 0,
Math.max(0, bottom - height), 0, height/2);
}