RecyclerView remove animation bug
Asked Answered
H

2

10

I have implemented a RecyclerView where I can add and delete items. I want the added item to be added on the second last position and, whenever I add a new item, the animation runs well. That is, the last item moves downwards, letting space for the new item to fade in.

When I remove an item there is a problem that I don't know how to fix. How I want it to behave is:

  1. fade out the deleted element,
  2. move upwards all the items below it.

What actually happens is that, first thing, the last item disappears, and then the rest of the animation takes place. When the items below the deleted element move upwards, the last item reappears as coming from behind a wall.

To me it seems as if the RecyclerView shrinks to the "post-animation" height, and then the animation is performed.

I haven't defined the ItemAnimator, so the DefaultItemAnimator must be the one used. I have watched this video, and overridden the supportsPredictiveItemAnimations method in a custom implementation of LinearLayoutManager, but it doesn't fix it.

Harsho answered 20/3, 2016 at 17:31 Comment(0)
E
5

I already reported the problem through Google Issue Tracker here

I hope we can get a fix soon! As you say It seems very related to a possible race condition between the measure updates for the recyclerview and the animation when your recyclerview is wrapping it's content to calculate it's height.

This article explains the problem in a really detailed way also.

Electrocardiograph answered 24/5, 2017 at 9:25 Comment(2)
Issue is closed with "Won't Fix (Intended behavior)" at May 25, 2017. Bug still present :(Pyrethrum
The linked article is helpful, basically don't use wrap_content on a RecylerView, bug still present in AndroidXCircularize
R
0

Perhaps a bit late, but I was able to fix this in my situation by setting the RecyclerView item animator to null, and then in the setList(list) function of my Adapter scheduling a Transition as such:

Transition transition = new AutoTransition();
transition.setDuration(200); // Or any duration you want
TransitionManager.beginDelayedTransition(mRootViewGroup, transition);

where mRootViewGroup is the viewgroup containing the RecyclerView.

This problem is also fixed by setting your layout_height (or width, depending on the scrolling orientation) to something other than wrap_content, but if, like me, you need your recyclerview height set to wrap_content, this might be a solution for you.

Not certain it will fix your problem as well, but I figured I might as well share what worked for me.

Reticle answered 9/1, 2021 at 9:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.