8

I am building a relatively simple RecyclerView, using a vertical LinearLayout Manager and a DefaultItemAnimator. It would only handle adding and removing items (no animated changes, swaps, moves, etc)

My items would be added at specific positions in the list because it is sorted in a certain order, and therefore the list has to scroll to the position where the item was added in order to show it to the user.

And there is the tricky part - the LinearLayoutManager and DefaultItemAnimator don't seem to be built to support predictive animations. Currently, due to the scrolling, all appearing items are animated, not just newly added ones, and I would like to run a specific animation only on the new item.

First, I have read the doc here, which says:

A LayoutManager wanting a better item animation experience, where items can be animated onto and off of the screen according to where the items exist when they are not on screen, then the LayoutManager should return true from supportsPredictiveItemAnimations() and add additional logic to onLayoutChildren(Recycler, State)

This is the doc for RecyclerView.LayoutManager, so LinearLayoutManager as a child should already have that additional logic (or not?)

The problem is that its onLayoutChildren method is way too complicated, and I'm not sure about what part exactly I should modify in order to differentiate "appearing on screen" from "brand new" views.

I have also read this tutorial, which adresses my exact problem, but the example uses a FixedGridLayoutManager, and yet again, I find it too complicated to understand and adapt the entire layout logic.

I am not looking for a ready copy-paste solution, but I need some clues about understanding the layout function. I'm afraid that writing my own one, besides being tedious, would necessarily produce a worse result, since there already are 200 lines of code in it, written by smarter people than me ^^

Ideally I would like to add something to it, or make small changes, in order not to break the whole measuring, scrapping, recycling, and whatever other complicated stuff is happening in there.

Thanks in advance, any help is welcome

Deliriom
  • 545
  • 4
  • 7
  • I believe I was in the same situation, and resolved it by swapping my raw `RecyclerView.Adapter` implementation for a `ListAdapter` implementation with a more-intelligent `DiffUtil.ItemCallback`. – stkent Aug 25 '21 at 13:23

0 Answers0