J'ai un ViewFlipper
qui contient deux mises en page. Ces deux mises en page ne contient qu'un seul ImageView
. Il y a une animation lorsque je fais défiler entre ces deux dispositions, mais pas l'animation triggerd avant que je lève le doigt, cela se produit à cause de cela:ViewFlipper animation
case MotionEvent.ACTION_UP:
//do animation
Comment puis-je modifier mon code pour l'animation est triggerd quand Je tenais mon doigt et glisser de gauche à droite et vice verca?
codesnippet pour faire l'animation:
@Override
public boolean onTouchEvent(MotionEvent touchevent) {
switch (touchevent.getAction())
{
case MotionEvent.ACTION_DOWN:
{
oldTouchValue = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP:
{
//if(this.searchOk==false) return false;
float currentX = touchevent.getX();
if (oldTouchValue < currentX)
{
vf.setInAnimation(inFromLeftAnimation());
vf.setOutAnimation(outToRightAnimation());
vf.showNext();
}
if (oldTouchValue > currentX)
{
vf.setInAnimation(inFromRightAnimation());
vf.setOutAnimation(outToLeftAnimation());
vf.showPrevious();
}
break;
}
}
return false;
}
//for the previous movement
public static Animation inFromRightAnimation() {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
inFromRight.setDuration(250);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}
public static Animation outToLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
outtoLeft.setDuration(250);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
// for the next movement
public static Animation inFromLeftAnimation() {
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
inFromLeft.setDuration(250);
inFromLeft.setInterpolator(new AccelerateInterpolator());
return inFromLeft;
}
public static Animation outToRightAnimation() {
Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f
);
outtoRight.setDuration(250);
outtoRight.setInterpolator(new AccelerateInterpolator());
return outtoRight;
}
Cela fonctionne un peu, mais je ne peux passer à la vue suivante une fois. Ex: Je suis dans la première vue, glisse mon doigt la deuxième vue montrera, si mon doigt est toujours sur l'écran, quand j'essaye de faire le geste inverse, glissant de la vue deux pour voir un sans relâcher mon doigt, ceci a gagné ne fonctionne pas. –
Une fois supprimer cette condition &&! IsDown et essayer. J'espère que cela aidera – Braj
Si je le fais, il va changer constamment la vue, très rapidement, quand je tiens mon doigt sur l'écran –