Android View 动画在屏幕外 View 时停止

标签 android xml animation view

我有一个带有多个 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/

相关文章:

java - 关于 JazzyListView Android

javascript - 如何在不使用 css 转换的情况下将 jQuery animate 与 css3 属性结合起来?

java - Android:ImageView 位于景观 Activity 的中心

android - 虚拟设备管理器意外退出,2 mac显示

javascript - 用于使用命名空间解析 XML 的 JavaScript 库?

java - 合并 list 失败

android - 对所有 API 级别应用相同的样式

swift - CAShapeLayer 动画不会触发 animationDidStop

android - android中TextView的放大、缩小和旋转

android - 我们可以解析数组元素和来自 android xml 数组的值吗