Animating item changes in RecyclerView doesn't work
See original GitHub issueI’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:
- Created 4 years ago
- Comments:10
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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());
I think this is a duplicate of #1324 which has more info