question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Animation canceling inside recyclerView

See original GitHub issue

Hi I’m using Lottie inside recyclerView.I put my json files inside asset folder.My goal is to play animation and when it finished then start activity.Here is a my source

`if (story.isRead) lottieAnimationView.setAnimation(“story_archive_gray.json”); else lottieAnimationView.setAnimation(“story_archive_blue.json”); rootView.setOnClickListener(view -> {

        lottieAnimationView.addAnimatorListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                SPLogger.logMassage("animationListener","onAnimationEnd");
                animation.cancel();
                //call activity
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                SPLogger.logMassage("animationListener","onAnimationCancel");

            }

            @Override
            public void onAnimationRepeat(Animator animation) {
                SPLogger.logMassage("animationListener","onAnimationRepeat");
            }
        });
        lottieAnimationView.playAnimation();

    });`

My problem is, sometimes can’t play animation successfully and onAnimationCancel called automatically .do you have any suggestion about my problem ? Thanks. Best regards

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16

github_iconTop GitHub Comments

4reactions
epekelcommented, Dec 11, 2019

@gpeal I am facing an opposite issue right now.

That is, if I play animation and scroll down in a RecyclerView before the animation finishes, and scroll back up, the animation plays from scratch again. I tried adding an animation listener and tried out some stuff in onAnimationCancel, such as setting the progress to 1f, pausing, cancelling, setting animation composition again, and a combination of these; but could not get it to work. I’m pretty sure it’s not because of my logic to play animation (i.e. the code to start the animation does not get called again). I think it might internally be about the visibility changes that might be overriding anything I do.

What I want to do is, if the animation is cancelled, I just wanna set the progress to 100% and show that as a static image. This works for the initial onBindViewHolder calls, because I do a similar thing for showing the current state of the image. Any ideas what could be going wrong? Would appreciate any help, thanks!

2reactions
haloSParkcommented, Apr 9, 2019

I also encountered this , ` override fun onBindViewHolder(holder: MyViewHolder, position: Int) { val moment = momentList[position]

    holder.videoView.prepare(moment.videoUrl)
    if (moment.isOwner()) {
        holder.deleteImageView.visibility = View.VISIBLE
    } else {
        holder.deleteImageView.visibility = View.INVISIBLE
    }
    holder.deleteImageView.setOnClickListener {
        deleteCallback?.invoke(holder.adapterPosition, moment)
    }
    holder.shareView.setOnClickListener {
        shareCallback?.invoke(moment)
    }

    holder.videoView.retryCallback = {
        holder.videoView.play(moment, holder.adapterPosition, true)
    }
    setupLikesData(holder, moment, position)
}

override fun onViewDetachedFromWindow(holder: MyViewHolder) {
    holder.videoView.stop()
}

private fun setupLikesData(
    holder: MyViewHolder,
    moment: Moment,
    position: Int
) {
    holder.giveLikesAnimationView.setAnimation("lottie/talentshow_give_like.json")
    holder.giveLikesAnimationView.speed = 0f
    if (moment.isLiked()) {
        holder.giveLikesAnimationView.progress = 1f
    } else {
        holder.giveLikesAnimationView.progress = 0f
    }
    holder.likesTextView.text = moment.likes.processLikesCount()
    holder.likesTextView.typeface = typeFace
    holder.giveLikesAnimationView.setOnClickListener {
        if (!moment.isLiked()) {
            holder.giveLikesAnimationView.speed = 1f
            holder.giveLikesAnimationView.playAnimation()
            likeCallback?.invoke(position, moment)
        } else {
            likeCallback?.invoke(position, moment)
        }
    }
}`,when i scoll the recyclerview,the animation doesn't play。
Read more comments on GitHub >

github_iconTop Results From Across the Web

Lottie Animation canceling automatically in Android
I'm using lottie animation inside my recyclerView.Here is a my source if (story.isRead) lottieAnimationView.
Read more >
Animations and Performance in Nested RecyclerViews - Reddit
To properly clean up the nested RecyclerView, release the ViewHolders back into the RecycledViewPool and to cancel running animations we ...
Read more >
DefaultItemAnimator - Android Developers
This implementation of RecyclerView.ItemAnimator provides basic animations on remove, add, and move events that happen to the items in a RecyclerView.
Read more >
RecyclerView animations - AndroidDevSummit write-up
It is worth recalling that RecyclerView. ItemAnimator is responsible only for animations between starting and final state of view. ...
Read more >
RecyclerView Animations – Add & Remove Items
RecyclerView is a really useful way of displaying content in list form, particularly when the content is dynamic and / or there are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found