Java 如何暂停和恢复动画?
我有一个圆形图像视图,我可以通过单击按钮开始旋转它,但我想在它停止在该位置时再次按下按钮。我该怎么做 这是Java 如何暂停和恢复动画?,java,android,animation,imageview,Java,Android,Animation,Imageview,我有一个圆形图像视图,我可以通过单击按钮开始旋转它,但我想在它停止在该位置时再次按下按钮。我该怎么做 这是动画 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator"> <rotate
动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<rotate
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360"
android:duration="10000"
android:repeatCount="infinite"
android:repeatMode="restart" />
</set>
谢谢! 这样试试看
private ObjectAnimator anim;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.property_animations_flow);
ImageView someImage = (ImageView) findViewById(R.id.some_image);
anim = ObjectAnimator.ofFloat(someImage, "rotation", 0, 360);
anim.setDuration(1000);
anim.setRepeatCount(5);
anim.setRepeatMode(ObjectAnimator.RESTART);
}
}
取决于你想在你的onclick中调用什么
anim.start() // start the animation from the beginning
anim.end() // end the animation
anim.cancel() // cancel the animation
anim.pause() // added in API 19; pause the animation
anim.resume() // added in API 19; resume a paused animation
它回到了旋转的开始
anim.start() // start the animation from the beginning
anim.end() // end the animation
anim.cancel() // cancel the animation
anim.pause() // added in API 19; pause the animation
anim.resume() // added in API 19; resume a paused animation