How do I animate the RecyclerView
when the items appear for first time and also when the user scrolls, just like the way it works for the google plus app or the google news stand app.
Also I read somewhere that RecyclerView
does not directly support animation when the user scrolls; if this is true, is there any way we can still do it?
I did it this way. Might help someone. I don't know whether it's the best way to do it but works fine for me.
UPDATE: To fix fast scrolling behaviour, override
onViewDetachedFromWindow
method of the adapter and callclearAnimation
on the animated view (in this case,holder.itemView.clearAnimation()
).Like this:up_from_bottom.xml
down_from_top.xml
And finally put this code in
onBindViewHolder
ofrecyclerView
. Create a field called lastPosition and initialize it to -1.https://github.com/wasabeef/recyclerview-animators
In my code is something like this:
You need to add dependencies to your gradle
Read teh doc form https://github.com/wasabeef/recyclerview-animators to install it.
Without any outside libraries in RecycleView.Adapter on method onBindViewHolder use animation like in example:
Above code will animate from bottom every row in list. Animation will be done only once, but onBindViewHolder is running on scrolling so first scrolling of list will be with animation effect.
Very important is to initialise view to start of animation, so in example i set:
then animation go backs to orginal position:
If you need alpha do this that way:
Use custom ItemAnimator with "slide up" animation for Add action. Like this - https://github.com/wasabeef/recyclerview-animators
For down_from_top.xml it should be