Animation for add not work with RecyclerView

Viewed 49

I custom animation for item in recycleView when it added/removed. But only animation when item remove working.Please help me.

 @Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    recyclerView.setItemAnimator(new DefaultItemAnimator() {
        @Override
        public boolean animateAdd(RecyclerView.ViewHolder holder) {
            Animation animation = AnimationUtils.loadAnimation(mContext, android.R.anim.slide_in_left);
            animation.setDuration(2000);
            holder.itemView.startAnimation(animation);
            return true;
        }
        @Override
        public boolean animateRemove(RecyclerView.ViewHolder holder) {
            holder.itemView.clearAnimation();
            holder.itemView.animate().alpha(0f).setDuration(2000).withLayer();
            return true;
        }
    });
}
0 Answers
Related