2015-10-07 70 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) 

希望它會幫助你。

乾杯!