0

J'ai vu beaucoup de questions mais je n'ai trouvé aucun motif similaire. J'ai fait des recherches beaucoup. J'ai une image avec est tourné à 36 °. J'ai utilisé setFillAfter() et setFillEnabled(). C'est en train de sauvegarder la position mais si je la fais tourner à nouveau, c'est à partir de la position d'origine. Je veux qu'il commence à la position où il était après la rotation.L'image commence à tourner à partir de la position de départ après un clic

Animation animation = new Animation (0,36, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); 
animation.setDuration(3000); 
animation.setInterpolator(new LinearInterpolator()); 
animation.setFillAfter(true); 

myImage.startAnimation(animation); 

Répondre

0

Vous avez juste besoin de passer l'angle actuel de imageview dans animation Constructor au lieu de 0 à chaque fois. Essayez ci-dessous le code:

 int rotationAngle=36;/*angle by which you want to rotate image*/ 
     int mCurrRotation = 0; /*current angle of image*/ 

     buttonRotate.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      float fromRotation = mCurrRotation; 
      float toRotation = mCurrRotation += rotationAngle; 

      Animation animation = new RotateAnimation(
        fromRotation, 
        toRotation, 
        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 


      animation.setDuration(3000); 
      animation.setFillAfter(true); 
      myImage.startAnimation(animation); 
     } 
    }); 
0

Pour cela après avoir effectué ensemble de rotation x coordonnée y de l'image nouvelle position où il a obtenu une rotation ...