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.

Animating item changes in RecyclerView doesn't work

See original GitHub issue

I’m using version 3.0.6

I call playAnimation() in onBindViewHolder() to play animation.

It works when I add item to RecyclerView, but does not work when there’s some changes and call notifyItemChanged().

After a while, I noticed that there’s some checks in LottieAnimationView.playAnimation().

if (isShown()) {
  lottieDrawable.playAnimation();
  enableOrDisableHardwareLayer();
} else {
  wasAnimatingWhenNotShown = true;
}

So I tried some debugs on it, and discovered that isShown() always returns false.

In order to play animation anyway, I should call LottieDrawable.playAnimation() directly, something like this:

fun LottieAnimationView.forcePlay() {
    (drawable as? LottieDrawable)?.playAnimation()
}

Is this an intended behavior, or not?

Issue Analytics

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

github_iconTop GitHub Comments

11reactions
venjiraicommented, Jul 1, 2019

I have the same problem. playAnimation inside onBindViewHolder does not work. I only works if I post it on the main thread.

lav.post(() -> lav.playAnimation());

0reactions
gpealcommented, Jul 31, 2019

I think this is a duplicate of #1324 which has more info

Read more comments on GitHub >

github_iconTop Results From Across the Web

MotionLayout animation item doesn't work inside RecyclerView
I found the problem: I had to control the MotionLayout animation completely from the Adapter inside onBindViewHolder(.
Read more >
RecyclerView Item Change Animations With a Custom Item ...
For item change animations, DefaultItemAnimator uses cross-fade animations. This makes sense, as recyclerview doesn't know what will change exactly.
Read more >
RecyclerView wrap_content height REMOVE item animation ...
So to me it seems like there is something wrong with the way the RecyclerView implementation is handling animations plus the way it's...
Read more >
RecyclerView Animations – Changing Items - Styling Android
For those that have converted from ListView there is a tendency to follow the same usage patterns when updating the data, but this...
Read more >
Create dynamic lists with RecyclerView - Android Developers
When an item scrolls off the screen, RecyclerView doesn't destroy its view. Instead, RecyclerView reuses the view for new items that have scrolled...
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