2015-10-07 37 views
0

我用旋转旋转动画。而在一定程度上的图像旋转图像在同一画面中,我想用户从以前的位置到下旋转相同的图像通过点击一个button.but什么发生旋转。机器人如何使用两次RotateAnimation

///inside oncreate 

RotateAnimation rotate = new RotateAnimation(0, rotateSpeed, 
         Animation.RELATIVE_TO_SELF, 0.9f, 
         Animation.RELATIVE_TO_SELF, 0.5f); 

       rotate.setDuration(4000); 
       rotate.setFillAfter(true); 
       imv.setAnimation(rotate); 

///inside button click 

RotateAnimation rotate = new RotateAnimation(start, start+end, 
       Animation.RELATIVE_TO_SELF, 0.9f, 
       Animation.RELATIVE_TO_SELF, 0.5f); 

     rotate.setDuration(2000); 
     rotate.setFillAfter(true); 
     imv.setAnimation(rotate); 
+1

嗨,考虑显示一些代码(并添加更好的标签!)。 –

+0

按照这个http://stackoverflow.com/questions/3760381/rotating-image-animation-list-or-animated-rotate-android –

回答

0

哦,我只是清除应用新的旋转动画之前已应用的旋转动画。

view.clearAnimation(); 
1

将您的视图和旋转值传递给此方法。希望这能解决你的问题。

public void rotateView(final View v, final int rotation) { 

    v.animate().setDuration(250).rotation(rotation).setListener(new AnimatorListenerAdapter() { 
     @Override 
     public void onAnimationStart(Animator animation) { 
      super.onAnimationStart(animation); 
     } 

     @Override 
     public void onAnimationCancel(Animator animation) { 
      super.onAnimationCancel(animation); 
     } 

     @Override 
     public void onAnimationEnd(Animator animation) { 
      super.onAnimationEnd(animation); 
     } 
    }); 
} 
0
RotateAnimation rotate = new RotateAnimation(0, 360, 
     Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 
     0.5f); 

rotate.setDuration(4000); 
rotate.setRepeatCount(-1); // here you can set repeatcoount 
yourView.setAnimation(rotate) 

希望它会帮助你。

干杯!