Created
July 18, 2015 07:04
-
-
Save shekaroppo/13460526894d7e2e2397 to your computer and use it in GitHub Desktop.
Track velocity in list view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean onTouchEvent(MotionEvent event) { | |
int action = event.getAction(); | |
switch(action) { | |
case MotionEvent.ACTION_DOWN: | |
if(vTracker == null) { | |
vTracker = VelocityTracker.obtain(); | |
} | |
else { | |
vTracker.clear(); | |
} | |
vTracker.addMovement(event); | |
break; | |
case MotionEvent.ACTION_MOVE: | |
vTracker.addMovement(event); | |
vTracker.computeCurrentVelocity(1000); | |
Log.v("", "X velocity is " + vTracker.getXVelocity() +" pixels per second"); | |
Log.v("", "Y velocity is " + vTracker.getYVelocity() +" pixels per second"); | |
break; | |
case MotionEvent.ACTION_UP: | |
case MotionEvent.ACTION_CANCEL: | |
vTracker.recycle(); | |
break; | |
} | |
return super.onTouchEvent(event); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment