Context: I have a ScrollView
that may have children added to its content view during a fling. Since the fling is configured with the height of the ScrollView<
To answer your questions from the prompt:
Looking at the ScrollView source code, it uses an OverScroller to handle the fling events. There are two ways of approaching this:
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.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);
}
I solved a similar problem with @Override
fling method. If you override fling
method on your ScrollViewNoFling
class and not call super.fling
on this method, you gonna have not-fling-handled scrollView
.
@Override
public void fling (int velocity)
{
/*Scroll view is no longer going to handle scroll velocity.
* super.fling(velocity);
*/
}