2015-04-23 2 views
0

Mon problème est d'essayer de comprendre comment arrêter l'animation pouvant être dessinée après avoir parcouru les images (par exemple en revenant à l'image des raisins). Je ne peux certainement pas utiliser la méthode que j'ai implémentée dans .ACTION.DOWN alors quelqu'un peut m'aider avec ça.Arrêt de l'animation pouvant être dessinée après la première boucle

public boolean onTouchEvent (MotionEvent event){ 
     Drawable currentFrame, checkFrame; 
     if (event.getAction() == MotionEvent.ACTION_DOWN) { 
      if (fruitAnimation.isRunning()) { 
       fruitAnimation.stop(); 
       //The variable that will guard the frame number 
       int frameNumber = 0; 
       //Get the frame of the animation 
       //Drawable currentFrame, checkFrame; 
       currentFrame = fruitAnimation.getCurrent(); 
       //checks the position of the frame. 
       for (int i = 0; i < fruitAnimation.getNumberOfFrames(); i++) { 
        checkFrame = fruitAnimation.getFrame(i); 
        if (checkFrame == currentFrame) { 
         frameNumber = i; 
         break; 
        } 

       } 
       String fruit = ""; 

       switch (frameNumber) { 
        case 0: 
         fruit = "Grapes"; 
         break; 
        case 1: 
         fruit = "Lemon"; 
         break; 
        case 2: 
         fruit = "Orange"; 
         break; 
        case 3: 
         fruit = "Pear"; 
         break; 
        case 4: 
         fruit = "Strawberry"; 
         break; 


       } 
       Toast.makeText(this, fruit, Toast.LENGTH_SHORT).show(); 

      }else { 
       fruitAnimation.start(); 


      } 
      return true; 
     } 

     return super.onTouchEvent(event); 
    } 

Répondre

1

Vous avez très probablement fait ce mauvais chemin. Puisqu'il y a animation listener que vous pouvez utiliser pour surveiller votre animation, je mettrais l'animation en une seule fois et ensuite dans mon écouteur, dans son onAnimationEnd() je vérifierais si j'atteignais ma limite et sinon, relancerais l'animation.

+0

J'ai choisi votre réponse puisque vous êtes le seul à avoir répondu à la question, mais ce que j'ai fait était d'ajouter 'android: oneshot =" true "' dans le fichier xml qui contenait mes images. – user827391012

+0

ah, c'est l'approche correcte. Je lis pour une raison que vous voulez arrêter votre animation après X jeux donnés. En tout cas, content que cela fonctionne pour vous –