Detect flight distance

I am working on an application that requires me to manually process the fling process, rather than providing it with a structure. What I want to achieve basically calculates the number of pixels that the listview moves when it receives the fling action. Since the scroll method already provides the distance in the form of a delta, I easily dealt with this. But is there any way to get the drop distance, since in the super method only the speed parameter is transmitted.

Note. I need to move another view according to the drop distance, so I need to get it at the same time as onScroll does. Thanks.

+6
source share
1 answer

3 years have passed, but no answer yet. I found some workaround to achieve it.

In fact, this is a kind of advanced topic, since there are many nuances, but basically you can reference the Android source code (in particular, the OverScroller class) and use this method. You will need to copy it to your class and use it.

private double getSplineFlingDistance(int velocity) { final double l = getSplineDeceleration(velocity); final double decelMinusOne = DECELERATION_RATE - 1.0; return mFlingFriction * PHYSICAL_COEF * Math.exp(DECELERATION_RATE / decelMinusOne * l); } 

Other methods and values ​​can be obtained from the same class. Source Code Link: https://android.googlesource.com/platform/frameworks/base/+/jb-release/core/java/android/widget/OverScroller.java

Keep in mind that on some devices the value may be different (not too much). Some manufacturers change the formula depending on their requirements and equipment to make it smoother.

+1
source

Source: https://habr.com/ru/post/970077/


All Articles