Example implementation on how to create expandable items in a RecyclerView.
MVVM
was used. The ViewModel
fetches data from a Repository
, transforms it and then exposes to the View
for it to observe through a LiveData
.
A compound view
was made to contain the layout used in each item in the RecyclerView
. This makes easier to get the necessary parts of the view to animate.
Was used ValueAnimator
to in each frame change the height of the item to give the impression of expanding/collapsing.
In the expand animation the RecyclerView
is moved along the animated item so if gets off screen, it gets back to it again.
Delay was used in the expand animation so it would start only after the animation of any other item closing.
DiffUtil
and Payloads
were used to indicate to a ViewHolder
than an item must be animated.