简体   繁体   English

无法在RecyclerView的Viewholder项目上停止动画

[英]Cannot stop animation on Viewholder item of RecyclerView

I'm having a hard time trying to stop animation on an item in my ViewHolder when scrolling the view away: When the view becomes visible, the animation works fine. 滚动视图时,我很难尝试在ViewHolder中的项目上停止动画:当视图变为可见时,动画可以正常工作。 However, when I scroll the view away and later come back to it, the animation is hung and cannot restart properly. 但是,当我将视图移开并稍后返回时,动画已挂起并且无法正确重新启动。 Please see the visual demo (around second 17) 请观看视觉演示 (大约第二个17)

I've tried a few ways to stop the animation, but none of them works. 我尝试了几种停止动画的方法,但是没有一种起作用。 My current implementation is in the following. 我当前的实现如下。

In my adapter: 在我的适配器中:

public void onViewAttachedToWindow(BaseViewHolder holder) {
    if (holder instanceof MyViewHolder) {
        holder.cancelAnimation();
        holder.setupAnimation();
    }
}

// cancelAnimation method in my ViewHolder
public void cancelAnimation() {
    if (myAnimatorSet != null) {
        myAnimatorSet.removeAllListeners();
        myAnimatorSet.end();
        myAnimatorSet.cancel();
    }
}

Perform View#clearAnimation() on the view that is being animated. 在要动画的视图上执行View#clearAnimation()

holder.someView.clearAnimation();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM