我有一个ImageView用作加载动画的旋转效果。当数据加载完毕后,我尝试停止动画,但是它并没有到达最后的状态就停了下来,反而在中途停住了,然后图像会突然回到原始状态,看起来很不好看。
以下是我尝试过的方法:
选项1:
三种情况的最终结果是相同的。我如何旋转图像并使其回到起始位置?
编辑:
一些进一步的信息:我的旋转动画:
以下是我尝试过的方法:
选项1:
ImageView iv = (ImageView) findViewById(R.id.refreshImage);
if (iv != null) {
iv.clearAnimation();
}
方案二:
ImageView iv = (ImageView) findViewById(R.id.refreshImage);
if (iv != null && iv.getAnimation() != null) {
iv.getAnimation().cancel();
}
选项3:
ImageView iv = (ImageView) findViewById(R.id.refreshImage);
if (iv != null && iv.getAnimation() != null) {
iv.getAnimation().setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
animation.cancel();
}
@Override
public void onAnimationEnd(Animation animation) {
}
});
}
三种情况的最终结果是相同的。我如何旋转图像并使其回到起始位置?
编辑:
一些进一步的信息:我的旋转动画:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />
我如何启动动画:
ImageView iv = (ImageView) findViewById(R.id.refreshImage);
Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotate);
rotation.setRepeatCount(Animation.INFINITE);
iv.startAnimation(rotation);