我有一个带有多个 View 的 recyclerView,其中一个是应用了动画的动画 View 。一旦 View 离开屏幕,动画就不再有效,尽管动画仍然存在。
数据:
rotate_around_center_point.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<rotate
android:duration="2500"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
</set>
应用动画:
animation = AnimationUtils.loadAnimation(this.getContext(),
R.anim.rotate_around_center_point);
loadingRotatingCircleIV.startAnimation(animation);
当动画被中断时,我找不到任何方法来捕捉事件,所以我能够在动画离开屏幕后重新启动它。
最佳答案
仅当您将 View 动画应用于该 View 时,当 View 从屏幕上消失时,RecyclerView 才会错误地停止 View 上的动画。如果您将使用 Property Animation,则一切正常。因此,以下解决方案将起作用:
ObjectAnimator animator = ObjectAnimator.ofFloat(loadingRotatingCircleIV, "rotation", 0.0f, 360.0f);
animator.setDuration(1000L);
animator.setRepeatCount(ObjectAnimator.INFINITE);
animator.setInterpolator(new LinearInterpolator());
animator.start();
关于Android View 动画在屏幕外 View 时停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26979683/