@Override protected void onAnimationCancel(@NonNull MoveAnimationInfo info, @NonNull RecyclerView.ViewHolder item) { final View view = item.itemView; final int deltaX = info.toX - info.fromX; final int deltaY = info.toY - info.fromY; if (deltaX != 0) { ViewCompat.animate(view).translationX(0); } if (deltaY != 0) { ViewCompat.animate(view).translationY(0); } if (deltaX != 0) { view.setTranslationX(0); } if (deltaY != 0) { view.setTranslationY(0); } }
/** * Animate offset * * @param child * @param offset */ private void animateOffset(final V child, final int offset, boolean forceAnimation, boolean withAnimation) { if (!behaviorTranslationEnabled && !forceAnimation) { return; } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { ensureOrCancelObjectAnimation(child, offset, withAnimation); translationObjectAnimator.start(); } else { ensureOrCancelAnimator(child, withAnimation); translationAnimator.translationY(offset).start(); } }
void start() { final View containerView = SwipeableViewHolderUtils.getSwipeableContainerView(mViewHolder); mInvSize = (1.0f / Math.max(1.0f, mHorizontal ? containerView.getWidth() : containerView.getHeight())); // setup animator mAnimator = ViewCompat.animate(containerView); mAnimator.setDuration(mDuration); mAnimator.translationX(mToX); mAnimator.translationY(mToY); if (mInterpolator != null) { mAnimator.setInterpolator(mInterpolator); } mAnimator.setListener(this); mAnimator.setUpdateListener(this); // start mActive.add(mViewHolder); mAnimator.start(); }
@Override protected void onCreateChangeAnimationForNewItem(@NonNull ChangeAnimationInfo info) { final ViewPropertyAnimatorCompat animator = ViewCompat.animate(info.newHolder.itemView); animator.translationX(0); animator.translationY(0); animator.setDuration(getDuration()); animator.alpha(1); startActiveItemAnimation(info, info.newHolder, animator); }
@Override protected void onCreateChangeAnimationForOldItem(@NonNull ChangeAnimationInfo info) { final ViewPropertyAnimatorCompat animator = ViewCompat.animate(info.oldHolder.itemView); animator.setDuration(getDuration()); animator.translationX(info.toX - info.fromX); animator.translationY(info.toY - info.fromY); animator.alpha(0); startActiveItemAnimation(info, info.oldHolder, animator); }
@Override protected void onCreateAnimation(@NonNull MoveAnimationInfo info) { final View view = info.holder.itemView; final int deltaX = info.toX - info.fromX; final int deltaY = info.toY - info.fromY; if (deltaX != 0) { ViewCompat.animate(view).translationX(0); } if (deltaY != 0) { ViewCompat.animate(view).translationY(0); } final ViewPropertyAnimatorCompat animator = ViewCompat.animate(view); animator.setDuration(getDuration()); startActiveItemAnimation(info, info.holder, animator); }
@Override protected void animateRemoveImpl(final RecyclerView.ViewHolder holder) { ViewCompat.animate(holder.itemView) .translationY(holder.itemView.getHeight() * .25f) .alpha(0) .setDuration(getRemoveDuration()) .setInterpolator(mInterpolator) .setListener(new DefaultRemoveVpaListener(holder)) .setStartDelay(getRemoveDelay(holder)) .start(); }
@Override protected void animateRemoveImpl(final RecyclerView.ViewHolder holder) { ViewCompat.animate(holder.itemView) .translationY(holder.itemView.getHeight()) .alpha(0) .setDuration(getRemoveDuration()) .setInterpolator(mInterpolator) .setListener(new DefaultRemoveVpaListener(holder)) .setStartDelay(getRemoveDelay(holder)) .start(); }
@Override protected void animateRemoveImpl(final RecyclerView.ViewHolder holder) { ViewCompat.animate(holder.itemView) .translationY(-holder.itemView.getHeight()) .alpha(0) .setDuration(getRemoveDuration()) .setInterpolator(mInterpolator) .setListener(new DefaultRemoveVpaListener(holder)) .setStartDelay(getRemoveDelay(holder)) .start(); }
@Override protected void animateRemoveImpl(final RecyclerView.ViewHolder holder) { ViewCompat.animate(holder.itemView) .translationY(-holder.itemView.getHeight() * .25f) .alpha(0) .setDuration(getRemoveDuration()) .setInterpolator(mInterpolator) .setListener(new DefaultRemoveVpaListener(holder)) .setStartDelay(getRemoveDelay(holder)) .start(); }
/** * Restore Bottom Navigation with or without animation * * @param withAnimation Boolean */ public void restoreBottomNavigation(boolean withAnimation) { if (bottomNavigationBehavior != null) { bottomNavigationBehavior.resetOffset(this, withAnimation); } else { // Show bottom navigation ViewCompat.animate(this) .translationY(0) .setInterpolator(new LinearOutSlowInInterpolator()) .setDuration(withAnimation ? 300 : 0) .start(); } }
ViewCompat.animate(view).setDuration(getChangeDuration()); oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX); oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY); oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() { @Override public void onAnimationStart(View view) { mChangeAnimations.add(changeInfo.newHolder); final ViewPropertyAnimatorCompat newViewAnimation = ViewCompat.animate(newView); newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration()). alpha(1).setListener(new VpaListenerAdapter() { @Override public void onAnimationStart(View view) {
ViewCompat.animate(view).translationY(0);
@Override protected void animateAddImpl(final RecyclerView.ViewHolder holder) { ViewCompat.animate(holder.itemView) .translationY(0) .alpha(1) .setDuration(getAddDuration()) .setInterpolator(mInterpolator) .setListener(new DefaultAddVpaListener(holder)) .setStartDelay(getAddDelay(holder)) .start(); } }
@Override protected void animateAddImpl(final RecyclerView.ViewHolder holder) { ViewCompat.animate(holder.itemView) .translationY(0) .alpha(1) .setDuration(getAddDuration()) .setInterpolator(mInterpolator) .setListener(new DefaultAddVpaListener(holder)) .setStartDelay(getAddDelay(holder)) .start(); } }
@Override protected void animateAddImpl(final RecyclerView.ViewHolder holder) { ViewCompat.animate(holder.itemView) .translationY(0) .alpha(1) .setDuration(getAddDuration()) .setInterpolator(mInterpolator) .setListener(new DefaultAddVpaListener(holder)) .setStartDelay(getAddDelay(holder)) .start(); } }
@Override protected void animateAddImpl(final RecyclerView.ViewHolder holder) { ViewCompat.animate(holder.itemView) .translationY(0) .alpha(1) .setDuration(getAddDuration()) .setInterpolator(mInterpolator) .setListener(new DefaultAddVpaListener(holder)) .setStartDelay(getAddDelay(holder)) .start(); } }
/** * Hide Bottom Navigation with or without animation * * @param withAnimation Boolean */ public void hideBottomNavigation(boolean withAnimation) { if (bottomNavigationBehavior != null) { bottomNavigationBehavior.hideView(this, bottomNavigationHeight, withAnimation); } else if (getParent() instanceof CoordinatorLayout) { needHideBottomNavigation = true; hideBottomNavigationWithAnimation = withAnimation; } else { // Hide bottom navigation ViewCompat.animate(this) .translationY(bottomNavigationHeight) .setInterpolator(new LinearOutSlowInInterpolator()) .setDuration(withAnimation ? 300 : 0) .start(); } }
public void setSwapTargetItem(RecyclerView.ViewHolder swapTargetItem) { if (mSwapTargetItem == swapTargetItem) { return; } // reset Y-translation if the swap target has been changed if (mSwapTargetItem != null) { ViewPropertyAnimatorCompat animator = ViewCompat.animate(mSwapTargetItem.itemView); animator.cancel(); animator.setDuration(10) .translationX(0) .translationY(0) .setListener(RESET_TRANSLATION_LISTENER) .start(); } mSwapTargetItem = swapTargetItem; if (mSwapTargetItem != null) { ViewPropertyAnimatorCompat animator = ViewCompat.animate(mSwapTargetItem.itemView); animator.cancel(); } mSwapTargetItemChanged = true; }
animator.setInterpolator(mReturnToDefaultPositionInterpolator); animator.translationX(0.0f); animator.translationY(0.0f); animator.translationZ(initialTranslationZ); animator.alpha(1.0f);