Back to project page RecyclerViewLib.
The source code is released under:
Apache License
If you think the Android project RecyclerViewLib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.twotoasters.anim; /*from w w w.j a v a 2s . c om*/ import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewPropertyAnimatorCompat; import android.view.View; import android.view.animation.AnticipateOvershootInterpolator; import android.view.animation.BounceInterpolator; import com.twotoasters.android.support.v7.widget.RecyclerView.LayoutParams; import com.twotoasters.android.support.v7.widget.RecyclerView.ViewHolder; import com.twotoasters.utils.DisplayUtils; public class SlideItemAnimator extends PendingItemAnimator { public SlideItemAnimator() { setAddDuration(1000); setRemoveDuration(500); setMoveDuration(500); } @Override protected boolean prepHolderForAnimateRemove(ViewHolder holder) { return true; } protected ViewPropertyAnimatorCompat animateRemoveImpl(ViewHolder holder) { final View view = holder.itemView; ViewCompat.animate(view).cancel(); return ViewCompat.animate(view) .translationX(DisplayUtils.getScreenDimensions(holder.itemView.getContext()).x) .setInterpolator(new AnticipateOvershootInterpolator()); } @Override protected void onRemoveCanceled(ViewHolder holder) { ViewCompat.setTranslationX(holder.itemView, 0); } @Override protected boolean prepHolderForAnimateAdd(ViewHolder holder) { int width = getWidth(holder); ViewCompat.setTranslationX(holder.itemView, width); return true; } protected ViewPropertyAnimatorCompat animateAddImpl(ViewHolder holder) { final View view = holder.itemView; ViewCompat.animate(view).cancel(); int width = getWidth(holder); return ViewCompat.animate(view) .translationXBy(-width) .setInterpolator(new BounceInterpolator()); } @Override protected void onAddCanceled(ViewHolder holder) { ViewCompat.setTranslationX(holder.itemView, 0); } public int getWidth(ViewHolder holder) { return getWidth(holder.itemView); } public int getWidth(View itemView) { return itemView.getMeasuredWidth() + itemView.getPaddingRight() + ((LayoutParams) itemView.getLayoutParams()).rightMargin; } }