我有一个名为infinite_rotation
的动画器,定义如下:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:propertyName="rotation"
android:repeatCount="infinite"
android:valueFrom="0"
android:valueTo="360"
android:duration="2000" />
</set>
当我不再需要这个东西时(时间不确定),我调用infinite_animator.cancel()
。然后在其布局容器上播放一个淡出动画。<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:propertyName="alpha"
android:repeatCount="0"
android:valueTo="0.0"
android:duration="1000" />
</set>
结果的动画是旋转停止,但在淡出时会出现卡顿。我错过了什么吗?这是它的样子:
![enter image description here](https://istack.dev59.com/QvQsU.gif)
这是动画调用:
private void animateRefreshButton() {
ImageView iv_refresh = (ImageView) findViewById(R.id.iv_refresh);
if(infinite_animator == null) {
infinite_animator = AnimatorInflater.loadAnimator(this, R.animator.refresh_rotate);
}
infinite_animator.setTarget(iv_refresh);
infinite_animator.start();
}
hideRefreshButton()
在应用程序确定刷新完成时被启动。这是取消并淡出动画的调用:
private void hideRefreshButton() {
if(infinite_animator != null) {
infinite_animator.cancel();
}
Animator anim = AnimatorInflater.loadAnimator(this, R.animator.refresh_fadeout);
anim.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {}
@Override
public void onAnimationEnd(Animator animation) {
framelayout_container_of_iv_refresh.setVisibility(View.GONE);
}
@Override
public void onAnimationCancel(Animator animation) {}
@Override
public void onAnimationRepeat(Animator animation) {}
});
anim.setTarget(framelayout_container_of_iv_refresh);
anim.start();
}