PaulNunezM PaulNunezM - 1 year ago 158
Android Question

How to animate RecyclerView items when they appear

How can I animate the RecyclerViews when there are appearing?

The default item animator only animates when a data is added or removed after the recycler data has been set. I'm new developing applications, and don't have any clue where to start.

Any ideas how to achieve this?

Answer Source


According to the ItemAnimator documentation :

This class defines the animations that take place on items as changes are made to the adapter.

So unless you add your items one by one to your RecyclerView and refresh the view at each iteration, I don't think ItemAnimator is the solution to your need.

Here is how you can animate the RecyclerView items when they appear using a CustomAdapter :

public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder>
    private Context context;

    // The items to display in your RecyclerView
    private ArrayList<String> items;
    // Allows to remember the last item shown on screen
    private int lastPosition = -1;

    public static class ViewHolder extends RecyclerView.ViewHolder
        TextView text;
        // You need to retrieve the container (ie the root ViewGroup from your custom_item_layout)
        // It's the view that will be animated
        FrameLayout container;

        public ViewHolder(View itemView)
            container = (FrameLayout) itemView.findViewById(;
            text = (TextView) itemView.findViewById(;

    public CustomAdapter(ArrayList<String> items, Context context)
        this.items = items;
        this.context = context;

    public CustomAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_item_layout, parent, false);
        return new ViewHolder(v);

    public void onBindViewHolder(ViewHolder holder, int position)

        // Here you apply the animation when the view is bound
        setAnimation(holder.container, position);

     * Here is the key method to apply the animation
    private void setAnimation(View viewToAnimate, int position)
        // If the bound view wasn't previously displayed on screen, it's animated
        if (position > lastPosition)
            Animation animation = AnimationUtils.loadAnimation(context, android.R.anim.slide_in_left);
            lastPosition = position;

And your custom_item_layout would look like this :




For more information about CustomAdapters and RecyclerView, refer to this training on the official documentation.

Problems on fast scroll

Using this method could cause problems with fast scrolling. The view could be reused while the animation is been happening. In order to avoid that is recommendable to clear the animation when is detached.

    public void onViewDetachedFromWindow(final RecyclerView.ViewHolder holder)

On CustomViewHolder:

    public void clearAnimation()

Old answer :

Give a look at Gabriele Mariotti's repo, I'm pretty sure you'll find what you need. He provides simple ItemAnimators for the RecyclerView, such as SlideInItemAnimator or SlideScaleItemAnimator.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download