Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android RecyclerView添加项动画_Android_Animation_Android Recyclerview - Fatal编程技术网

Android RecyclerView添加项动画

Android RecyclerView添加项动画,android,animation,android-recyclerview,Android,Animation,Android Recyclerview,我目前正在为RecyclerView项目添加收入动画。我想要它就像谷歌+安卓应用一样。以下是我的代码片段: anim/up\u from\u bottom.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="@android:anim/decelerate

我目前正在为RecyclerView项目添加收入动画。我想要它就像谷歌+安卓应用一样。以下是我的代码片段:

anim/up\u from\u bottom.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:shareInterpolator="@android:anim/decelerate_interpolator">

    <translate
        android:fromXDelta="0%" android:toXDelta="0%"
        android:fromYDelta="60%" android:toYDelta="0%"
        android:duration="500" />
</set>
startAnimation是这样的:

protected void startAnimation(View view, int position) {
    if (position > lastPosition) {
        Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.up_from_bottom);
        view.startAnimation(animation);
        lastPosition = position;
    }
}
它看起来像Google+Android应用程序的列表动画,但它有一个bug,当我快速滚动时,它的动画效果并不完美,比如第一个位置和当前位置似乎同时执行动画

我只想要像Google+一样的动画,我如何修复它,或者还有其他方法

我已经试过了,这是一个很好的自由,但我仍然做我想做的


请帮忙!谢谢

快速滚动时会出现错误,因为从显示中滚动出时,viewholder上的动画仍在运行,而当recyclerview将其回收时,您正在将新动画绑定到viewholder

您应该覆盖onViewDetachedFromWindow并清除方法中视图上的动画


这将确保在视图上运行的任何动画在发送到回收器进行恢复之前都将被清除,您可以安全地在视图上运行新动画。

当您快速滚动时,会出现错误,因为当从显示中滚动出来时,viewholder上的动画仍在运行,并且当recyclerview将新动画循环使用时,您正在将其绑定到viewholder

您应该覆盖onViewDetachedFromWindow并清除方法中视图上的动画

这将确保在视图上运行的任何动画在发送到回收器进行恢复之前都将被清除,并且您可以安全地在视图上运行新动画

protected void startAnimation(View view, int position) {
    if (position > lastPosition) {
        Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.up_from_bottom);
        view.startAnimation(animation);
        lastPosition = position;
    }
}