Hi everyone, in my app there's a ViewFlipper that shows 3 different layouts, and the user can switch between them (the new one comes in from the left, the old one goes out to the right, and vice versa) by using two Buttons.
I wanted to give the user a chance to simply press the screen, move the finger, and release it, to switch between the same layouts.
So I attached the ViewFlipper to this onTouchListener:
If I call the same methods on flipper in the Buttons' onClick() callback, the animation works fine.
But in this, it doesn't work right, it always moves to the left. And it also moves if you just click on the screen without moving the finger (it should move only if you moved the finger more than 50 pixels).
Do you have an idea why?
Thanks!
Simone
I wanted to give the user a chance to simply press the screen, move the finger, and release it, to switch between the same layouts.
So I attached the ViewFlipper to this onTouchListener:
Code:
public boolean onTouch(View v, MotionEvent event) {
float startx=0, endx=0;
ViewFlipper flipper=(ViewFlipper)v;
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
startx=event.getRawX();
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
endx=event.getRawX();
if(endx-startx > 50){
//move to the left
flipper.setInAnimation(Animations.inFromLeftAnimation());
flipper.setOutAnimation(Animations.outToRightAnimation());
flipper.showPrevious();
}
else if(startx-endx > 50){
//move to the right
flipper.setInAnimation(Animations.inFromRightAnimation());
flipper.setOutAnimation(Animations.outToLeftAnimation());
flipper.showNext();
}
break;
}
If I call the same methods on flipper in the Buttons' onClick() callback, the animation works fine.
But in this, it doesn't work right, it always moves to the left. And it also moves if you just click on the screen without moving the finger (it should move only if you moved the finger more than 50 pixels).
Do you have an idea why?
Thanks!
Simone