Search code examples
androidscrollsurfaceviewglsurfaceviewsmooth-scrolling

calculating velocity


Im trying to implement inertial scrolling in my GLSurfaceView and to do that i need to figure out how to calculate velocity, but im not sure how to do so. the translation is stored in a matrix, and it is calculated by the line of code below.

matrix.postTranslate(event.getX() - start.x,event.getY() - start.y);

Solution

  • Take a look at the Scroller and VelocityTracker classes. Together they are used to implement fling behavior in the standard framework widgets. Use these and your app will always match the native feel of the device.