Some time ago I started to write some kind of a list view for my purposes and yesterday I became frustrated due to something strange happening with my scrolling behaviour.
I have read the source code of the default android.widget.Scroller
class implementation and noticed that things were simplier than they seems to be. There are laws of kinematics taken as stone. Unfortunately, when I decided to increase deceleration at some point while flinging I noticed that current velocity was not always calculated correctly. After review of the Scroller source code I realized that the current velocity was always calculated incorrectly. There is a hiden method that calculates current velocity of the scroller:
/**
* @hide
* Returns the current velocity.
*
* @return The original velocity less the deceleration. Result may be
* negative.
*/
public float getCurrVelocity() {
return mVelocity - mDeceleration * timePassed() / 2000.0f;
}
As you can see there is Vfinal = Vsource - a * t / 2
... but what is division by 2 for???
Since I have changed it to the phisically correct method
public float getCurrVelocity() {
return mVelocity - mDeceleration * timePassed() / 1000.0f;
}
My sping effect works fine.
So the question is why there is division by 2? Or is it just a mistake since this method is hidden and wasn't called locally inside the Scroller class?