Viewpager's Fakedragby() Or Setcurrentitem() Doesn't Snap To Current Item
Resolved. See answer marked as correct along with my comments. Can post example code if necessary I'm using the VelocityViewPager to implement a 'fling' behavior. There is a kn
Solution 1:
I have found a workaround. I track what movement was done previously, and when a MotionEvent.ACTION_UP
occurs I trigger a new fling. I am not sure, if it's logically correct this way (is this the good direction? and is this a good velocity for a new fling?), but I tested it, and it works:
private boolean isLeftDirection = false;
@Override
public boolean onTouchEvent(MotionEvent event) {
// give all the events to the gesture detector. I'm returning true here
// so the viewpager doesn't
// get any events at all, I'm sure you could adjust this to make that
// not true.
if (event.getAction() == MotionEvent.ACTION_UP) {
int id = getCurrentItem();
setCurrentItem(id, true);
if (isLeftDirection){
mFlingRunnable.startUsingVelocity((int) 1);
} else {
mFlingRunnable.startUsingVelocity((int) -1);
}
}
mGestureDetector.onTouchEvent(event);
return true;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distX,
float distY) {
trackMotion(-distX);
if (distX > 0){
isLeftDirection = true;}
else{
isLeftDirection = false;
}
return false;
}
Post a Comment for "Viewpager's Fakedragby() Or Setcurrentitem() Doesn't Snap To Current Item"