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
contents before those children are added, if children get added then the fling stops itself (and actually scrolls backwards a bit because of overscroll) even though it hasn't reached the bottom of the contents.
I can possibly restart the fling using #fling(int velocity)
, but I can't figure out a way to get the current fling velocity or stop the current fling. Any ideas?
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With