旋转动画

问题描述:

我尝试旋转的ImageView与animation.i写了一些代码。此是我的XML动画代码旋转动画

<rotate 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:fromDegrees="0" 
android:toDegrees="360" 
android:pivotX="50%" 
android:pivotY="50%" 
android:repeatCount="infinite" /> 

,这是一个java代码

 final ImageView myImage = (ImageView)findViewById(R.id.rot); 
    final Animation myRotation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotator); 

    myImage.setAnimation(myRotation); 

    Handler ha=new Handler(); 
    ha.postDelayed(new Runnable() { 

     @Override 
     public void run() { 
      myRotation.setDuration(1000); 

     } 

    }, 1000); 
    myRotation.cancel(); 

我尝试取消动画持续时间结束,但我可以旋转ImageView,但我无法取消动画 我该如何解决我的问题?如果有人知道的解决方案,请帮助我

+0

更改它的重复次数。 – savepopulation 2014-09-29 13:48:10

你并不需要使用处理程序动画。

只要使用此:

动画XML:

<rotate 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fromDegrees="0" 
    android:toDegrees="360" 
    android:pivotX="50%" 
    android:pivotY="50%" 
    android:repeatCount="1" 
    android:duration="1000"/> 

在活动:

myImage.startAnimation(myRotation); //this will stop animation after 1000 miliseconds as `repeatCount` is 1. 

希望它能帮助。

+0

感谢它working.it是一个可能检查动画spead.i知道如何检查动画splead,但我的意思是,动画spead自动减速 – Beka 2014-09-29 13:52:55

+0

这可能取决于程度和关键。 @Beka – 2014-09-30 04:19:57

尝试这些:

myImage.startAnimation(myRotation); // to start animation 
myImage.cancelAnimation(); // to cancel animation