Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Android RecyclerView sequential items fade-in animation
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.view.View;
public class MyAlphaInAnimationAdapter extends MyAnimationAdapter {
private static final float DEFAULT_ALPHA_FROM = 0.0F;
private final float mFrom;
private RecyclerView recyclerView;
public MyAlphaInAnimationAdapter(RecyclerView.Adapter adapter) {
this(adapter, 0.0F);
public MyAlphaInAnimationAdapter(RecyclerView.Adapter adapter, float from) {
this.mFrom = from;
protected Animator[] getAnimators(View view) {
return new Animator[]{ObjectAnimator.ofFloat(view, "alpha", new float[]{this.mFrom, 1.0F})};
protected RecyclerView getRecyclerView() {
return recyclerView;
public void setRecyclerView(RecyclerView recyclerView) {
this.recyclerView = recyclerView;
import android.animation.Animator;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
public abstract class MyAnimationAdapter extends Adapter<ViewHolder> {
private Adapter<ViewHolder> mAdapter;
private int mDuration = 300;
private Interpolator mInterpolator = new LinearInterpolator();
private int mLastPosition = -1;
private boolean isFirstOnly = true;
private int mCounter;
private boolean mAnimsInitialized;
public MyAnimationAdapter(Adapter<ViewHolder> adapter) {
this.mAdapter = adapter;
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return this.mAdapter.onCreateViewHolder(parent, viewType);
public void onBindViewHolder(ViewHolder holder, int position) {
this.mAdapter.onBindViewHolder(holder, position);
if(this.isFirstOnly && position <= this.mLastPosition) {
} else {
Animator[] animators = this.getAnimators(holder.itemView);
int animArrLength = animators.length;
LinearLayoutManager layoutManager = ((LinearLayoutManager)this.getRecyclerView().getLayoutManager());
int firstVisiblePosition = layoutManager.findFirstVisibleItemPosition();
if (mAnimsInitialized == false && firstVisiblePosition == 0)
for (int i = 0; i < animArrLength; i++) {
final Animator anim = animators[i];
anim.setDuration((long) this.mDuration);
anim.setStartDelay(75 * position);
anim.addListener(new Animator.AnimatorListener() {
@Override public void onAnimationStart(Animator animation) {}
public void onAnimationEnd(Animator animation) {
if (decreaseCounter())
mAnimsInitialized = true;
@Override public void onAnimationCancel(Animator animation) {}
@Override public void onAnimationRepeat(Animator animation) {}
this.mLastPosition = position;
protected synchronized boolean decreaseCounter() {
return mCounter == 0;
public synchronized int getCounter() {
return mCounter;
public synchronized void increaseCounter() {
public int getItemCount() {
return this.mAdapter.getItemCount();
public void setDuration(int duration) {
this.mDuration = duration;
public void setInterpolator(Interpolator interpolator) {
this.mInterpolator = interpolator;
public void setStartPosition(int start) {
this.mLastPosition = start;
protected abstract Animator[] getAnimators(View var1);
protected abstract RecyclerView getRecyclerView();
public void setFirstOnly(boolean firstOnly) {
this.isFirstOnly = firstOnly;
public int getItemViewType(int position) {
return this.mAdapter.getItemViewType(position);
public Adapter<ViewHolder> getWrappedAdapter() {
return this.mAdapter;
import android.view.View;
import android.view.animation.Interpolator;
public final class MyViewHelper {
public static void clear(View v) {
ViewCompat.setAlpha(v, 1.0F);
ViewCompat.setScaleY(v, 1.0F);
ViewCompat.setScaleX(v, 1.0F);
ViewCompat.setTranslationY(v, 0.0F);
ViewCompat.setTranslationX(v, 0.0F);
ViewCompat.setRotation(v, 0.0F);
ViewCompat.setRotationY(v, 0.0F);
ViewCompat.setRotationX(v, 0.0F);
v.setPivotY((float)(v.getMeasuredHeight() / 2));
ViewCompat.setPivotX(v, (float)(v.getMeasuredWidth() / 2));
RecyclerView myRecyclerView = getActivity().findViewById(;
FavoriteItemsListAdapter myAdapter = new FavoriteItemsListAdapter();
MyAlphaInAnimationAdapter alphaInAnimationAdapter = new MyAlphaInAnimationAdapter(myAdapter);

This comment has been minimized.

Copy link
Owner Author

kosiara commented Sep 4, 2015

This adapter aims to create a sequential RecyclerView items' animation.
Items appear in order, top to bottom. The animation works when the RecyclerView is first created and does NOT work when items are scrolled down.

Performance is good to average. I wouldn't recommend using alpha-in animation on older phones.

Live preview:

Live preview


This comment has been minimized.

Copy link
Owner Author

kosiara commented Sep 4, 2015

Image 1

Image 2

Image 3

Image 4


This comment has been minimized.

Copy link

usmanrana07 commented Jun 12, 2018

Can you highlight the major difference than this one? i found a similar adapter at given link:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.