private void animateRemoveImpl(final ViewHolder holder) { final View view = holder.itemView; final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); animation .setDuration(getRemoveDuration()) .alpha(0) .setListener( new VpaListenerAdapter() { @Override public void onAnimationStart(View view) { dispatchRemoveStarting(holder); } @Override public void onAnimationEnd(View view) { animation.setListener(null); ViewCompat.setAlpha(view, 1); dispatchRemoveFinished(holder); mRemoveAnimations.remove(holder); dispatchFinishedWhenDone(); } }) .start(); mRemoveAnimations.add(holder); }
private void animateMoveImpl(final ViewHolder holder, int fromX, int fromY, int toX, int toY) { final View view = holder.itemView; final int deltaX = toX - fromX; final int deltaY = toY - fromY; if (deltaX != 0) { ViewCompat.animate(view).translationX(0); } if (deltaY != 0) { ViewCompat.animate(view).translationY(0); } // TODO: make EndActions end listeners instead, since end actions aren't // called when // vpas are canceled (and can't end them. why?) // need listener functionality in VPACompat for this. Ick. mMoveAnimations.add(holder); final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); animation .setDuration(getMoveDuration()) .setListener( new VpaListenerAdapter() { @Override public void onAnimationStart(View view) { dispatchMoveStarting(holder); } @Override public void onAnimationCancel(View view) { if (deltaX != 0) { ViewCompat.setTranslationX(view, 0); } if (deltaY != 0) { ViewCompat.setTranslationY(view, 0); } } @Override public void onAnimationEnd(View view) { animation.setListener(null); dispatchMoveFinished(holder); mMoveAnimations.remove(holder); dispatchFinishedWhenDone(); } }) .start(); }
private void animateRemoveImpl(final ViewHolder holder) { final View view = holder.itemView; int position = (int) view.getTag(); final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); float endX, endY; if (position % 2 == 0) { endY = -100; endX = -width; } else { endY = 100; endX = width; } mRemoveAnimations.add(holder); animation.setInterpolator(new AnticipateOvershootInterpolator()); animation .setDuration(getRemoveDuration()) .alpha(0) .translationX(endX) .translationY(endY) .setListener( new VpaListenerAdapter() { @Override public void onAnimationStart(View view) { dispatchRemoveStarting(holder); } @Override public void onAnimationEnd(View view) { animation.setListener(null); // 重置为正常 ViewCompat.setAlpha(view, 1); ViewCompat.setTranslationX(view, 0); ViewCompat.setTranslationY(view, 0); dispatchRemoveFinished(holder); mRemoveAnimations.remove(holder); dispatchFinishedWhenDone(); } }) .start(); }
void start() { final View containerView = ((SwipeableItemViewHolder) mViewHolder).getSwipeableContainerView(); 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(); }
protected void animateRemoveImpl(final RecyclerView.ViewHolder holder) { View view = holder.itemView; final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); this.mRemoveAnimations.add(holder); animation .setDuration(this.getRemoveDuration()) .alpha(0.0F) .setListener( new VpaListenerAdapter() { public void onAnimationStart(View view) { dispatchRemoveStarting(holder); } public void onAnimationEnd(View view) { animation.setListener((ViewPropertyAnimatorListener) null); ViewCompat.setAlpha(view, 1.0F); dispatchRemoveFinished(holder); mRemoveAnimations.remove(holder); dispatchFinishedWhenDone(); } }) .start(); }
@Override public ViewPropertyAnimatorCompat removeAnimation(View view) { final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); return animation.setDuration(getMoveDuration()).alpha(0).translationX(-view.getWidth()); }