Java Code Examples for androidx.core.view.ViewCompat#setTranslationX()
The following examples show how to use
androidx.core.view.ViewCompat#setTranslationX() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseItemAnimator.java From recyclerview-animators with Apache License 2.0 | 6 votes |
@Override public boolean animateMove(final ViewHolder holder, int fromX, int fromY, int toX, int toY) { final View view = holder.itemView; fromX += ViewCompat.getTranslationX(holder.itemView); fromY += ViewCompat.getTranslationY(holder.itemView); endAnimation(holder); int deltaX = toX - fromX; int deltaY = toY - fromY; if (deltaX == 0 && deltaY == 0) { dispatchMoveFinished(holder); return false; } if (deltaX != 0) { ViewCompat.setTranslationX(view, -deltaX); } if (deltaY != 0) { ViewCompat.setTranslationY(view, -deltaY); } mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY)); return true; }
Example 2
Source File: PendingItemAnimator.java From FlexibleAdapter with Apache License 2.0 | 6 votes |
/** * Do whatever you need to do before animation. **/ protected boolean prepHolderForAnimateMove(final H holder, int fromX, int fromY, int toX, int toY) { final View view = holder.itemView; int deltaX = toX - fromX; int deltaY = toY - fromY; if (deltaX == 0 && deltaY == 0) { dispatchMoveFinished(holder); return false; } if (deltaX != 0) { ViewCompat.setTranslationX(view, -deltaX); } if (deltaY != 0) { ViewCompat.setTranslationY(view, -deltaY); } return true; }
Example 3
Source File: BaseItemAnimator.java From recyclerview-animators with Apache License 2.0 | 6 votes |
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, ViewHolder item) { boolean oldItem = false; if (changeInfo.newHolder == item) { changeInfo.newHolder = null; } else if (changeInfo.oldHolder == item) { changeInfo.oldHolder = null; oldItem = true; } else { return false; } ViewCompat.setAlpha(item.itemView, 1); ViewCompat.setTranslationX(item.itemView, 0); ViewCompat.setTranslationY(item.itemView, 0); dispatchChangeFinished(item, oldItem); return true; }
Example 4
Source File: PendingItemAnimator.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
@Override public void endAnimation(ViewHolder item) { final View view = item.itemView; ViewCompat.animate(view).cancel(); if (mPendingMoves.contains(item)) { ViewCompat.setTranslationY(view, 0); ViewCompat.setTranslationX(view, 0); dispatchMoveFinished(item); mPendingMoves.remove(item); } if (mPendingRemovals.contains(item)) { dispatchRemoveFinished(item); mPendingRemovals.remove(item); } if (mPendingAdditions.contains(item)) { dispatchAddFinished(item); mPendingAdditions.remove(item); } if (mMoveAnimations.contains(item)) { ViewCompat.setTranslationY(view, 0); ViewCompat.setTranslationX(view, 0); dispatchMoveFinished(item); mMoveAnimations.remove(item); } if (mRemoveAnimations.contains(item)) { dispatchRemoveFinished(item); mRemoveAnimations.remove(item); } if (mAddAnimations.contains(item)) { dispatchAddFinished(item); mAddAnimations.remove(item); } dispatchFinishedWhenDone(); }
Example 5
Source File: IModeActivity.java From AndroidAnimationExercise with Apache License 2.0 | 5 votes |
@Override public void transformPage(View view, float position) { if (position < -1) { } else if (position <= 0) { ViewCompat.setTranslationX(view, -view.getWidth() * position); ViewCompat.setPivotX(view, view.getWidth() * 0.5f); ViewCompat.setPivotY(view, view.getHeight() * 0.5f); ViewCompat.setScaleX(view, 1 + position); ViewCompat.setScaleY(view, 1 + position); if (position < -0.95f) { ViewCompat.setAlpha(view, 0); } else { ViewCompat.setAlpha(view, 1); } } else if (position <= 1) { ViewCompat.setTranslationX(view, -view.getWidth() * position); ViewCompat.setPivotX(view, view.getWidth() * 0.5f); ViewCompat.setPivotY(view, view.getHeight() * 0.5f); ViewCompat.setScaleX(view, 1 - position); ViewCompat.setScaleY(view, 1 - position); if (position > 0.95f) { ViewCompat.setAlpha(view, 0); } else { ViewCompat.setAlpha(view, 1); } } }
Example 6
Source File: SwipeListViewTouchListener.java From UltimateRecyclerView with Apache License 2.0 | 5 votes |
/** * Will delete all pending dismisses. * Will call callback onDismiss for all pending dismisses. * Will reset all cell height to originalHeight. * * @param originalHeight is the height of the cell before animation. */ private void removePendingDismisses(int originalHeight) { // No active animations, process all pending dismisses. // Sort by descending position Collections.sort(pendingDismisses); int[] dismissPositions = new int[pendingDismisses.size()]; for (int i = pendingDismisses.size() - 1; i >= 0; i--) { dismissPositions[i] = pendingDismisses.get(i).position; } swipeListView.onDismiss(dismissPositions); ViewGroup.LayoutParams lp; for (PendingDismissData pendingDismiss : pendingDismisses) { // Reset view presentation if (pendingDismiss.view != null) { ViewCompat.setAlpha(pendingDismiss.view, 1f); ViewCompat.setTranslationX(pendingDismiss.view, 0); lp = pendingDismiss.view.getLayoutParams(); lp.height = originalHeight; pendingDismiss.view.setLayoutParams(lp); } } resetPendingDismisses(); }
Example 7
Source File: FlipDownItemAnimator.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
@Override protected void onRemoveCanceled(ViewHolder holder) { ViewCompat.setRotationY(holder.itemView, 0); ViewCompat.setTranslationX(holder.itemView, 0); ViewCompat.setScaleX(holder.itemView, 1); ViewCompat.setScaleY(holder.itemView, 1); }
Example 8
Source File: BaseItemAnimator.java From recyclerview-animators with Apache License 2.0 | 5 votes |
@Override public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY, int toX, int toY) { if (oldHolder == newHolder) { // Don't know how to run change animations when the same view holder is re-used. // run a move animation to handle position changes. return animateMove(oldHolder, fromX, fromY, toX, toY); } final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView); final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView); final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView); endAnimation(oldHolder); int deltaX = (int) (toX - fromX - prevTranslationX); int deltaY = (int) (toY - fromY - prevTranslationY); // recover prev translation state after ending animation ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX); ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY); ViewCompat.setAlpha(oldHolder.itemView, prevAlpha); if (newHolder != null && newHolder.itemView != null) { // carry over translation values endAnimation(newHolder); ViewCompat.setTranslationX(newHolder.itemView, -deltaX); ViewCompat.setTranslationY(newHolder.itemView, -deltaY); ViewCompat.setAlpha(newHolder.itemView, 0); } mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY)); return true; }
Example 9
Source File: FlipDownItemAnimator.java From FlexibleAdapter with Apache License 2.0 | 4 votes |
@Override protected boolean prepHolderForAnimateAdd(ViewHolder holder) { ViewCompat.setTranslationX(holder.itemView, -(holder.itemView.getMeasuredWidth() / 2)); ViewCompat.setRotationY(holder.itemView, -90); return true; }
Example 10
Source File: FadeInRightAnimator.java From recyclerview-animators with Apache License 2.0 | 4 votes |
@Override protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) { ViewCompat.setTranslationX(holder.itemView, holder.itemView.getRootView().getWidth() * .25f); ViewCompat.setAlpha(holder.itemView, 0); }
Example 11
Source File: SlideInRightAnimator.java From recyclerview-animators with Apache License 2.0 | 4 votes |
@Override protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) { ViewCompat.setTranslationX(holder.itemView, holder.itemView.getRootView().getWidth()); }
Example 12
Source File: PendingItemAnimator.java From FlexibleAdapter with Apache License 2.0 | 4 votes |
/** * This should reset the move animation. **/ protected void onMoveCanceled(ViewHolder holder) { ViewCompat.setTranslationX(holder.itemView, 0); ViewCompat.setTranslationY(holder.itemView, 0); }
Example 13
Source File: SlideItemAnimator.java From FlexibleAdapter with Apache License 2.0 | 4 votes |
@Override protected void onAddCanceled(ViewHolder holder) { ViewCompat.setTranslationX(holder.itemView, 0); }
Example 14
Source File: SlideItemAnimator.java From FlexibleAdapter with Apache License 2.0 | 4 votes |
@Override protected void onRemoveCanceled(ViewHolder holder) { ViewCompat.setTranslationX(holder.itemView, 0); }
Example 15
Source File: FadeInLeftAnimator.java From recyclerview-animators with Apache License 2.0 | 4 votes |
@Override protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) { ViewCompat.setTranslationX(holder.itemView, -holder.itemView.getRootView().getWidth() * .25f); ViewCompat.setAlpha(holder.itemView, 0); }
Example 16
Source File: SwipeListViewTouchListener.java From UltimateRecyclerView with Apache License 2.0 | 4 votes |
/** * Moves the view * * @param deltaX delta */ public void move(float deltaX) { swipeListView.onMove(downPosition, deltaX); float posX = ViewCompat.getX(frontView); if (opened.get(downPosition)) { posX += openedRight.get(downPosition) ? -viewWidth + rightOffset : viewWidth - leftOffset; } if (posX > 0 && !swipingRight) { if (SwipeListView.DEBUG) { Log.d(SwipeListView.TAG, "change to right"); } swipingRight = !swipingRight; swipeCurrentAction = swipeActionRight; if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) { backView.setVisibility(View.GONE); } else { backView.setVisibility(View.VISIBLE); } } if (posX < 0 && swipingRight) { if (SwipeListView.DEBUG) { Log.d(SwipeListView.TAG, "change to left"); } swipingRight = !swipingRight; swipeCurrentAction = swipeActionLeft; if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) { backView.setVisibility(View.GONE); } else { backView.setVisibility(View.VISIBLE); } } if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_DISMISS) { ViewCompat.setTranslationX(parentView, deltaX); ViewCompat.setAlpha(parentView, Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / viewWidth))); } else if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) { if ((swipingRight && deltaX > 0 && posX < DISPLACE_CHOICE) || (!swipingRight && deltaX < 0 && posX > -DISPLACE_CHOICE) || (swipingRight && deltaX < DISPLACE_CHOICE) || (!swipingRight && deltaX > -DISPLACE_CHOICE)) { ViewCompat.setTranslationX(frontView, deltaX); } } else { ViewCompat.setTranslationX(frontView, deltaX); } }
Example 17
Source File: SlideInLeftAnimator.java From recyclerview-animators with Apache License 2.0 | 4 votes |
@Override protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) { ViewCompat.setTranslationX(holder.itemView, -holder.itemView.getRootView().getWidth()); }
Example 18
Source File: ItemTouchUIUtilImpl.java From CrazyDaily with Apache License 2.0 | 4 votes |
@Override public void onDraw(Canvas c, RecyclerView recyclerView, View view, float dX, float dY, int actionState, boolean isCurrentlyActive) { ViewCompat.setTranslationX(view, dX); ViewCompat.setTranslationY(view, dY); }
Example 19
Source File: ItemTouchUIUtilImpl.java From CrazyDaily with Apache License 2.0 | 4 votes |
@Override public void clearView(View view) { ViewCompat.setTranslationX(view, 0f); ViewCompat.setTranslationY(view, 0f); }
Example 20
Source File: ItemTouchUIUtilImpl.java From monero-wallet-android-app with MIT License | 4 votes |
@Override public void onDraw(Canvas c, RecyclerView recyclerView, View view, float dX, float dY, int actionState, boolean isCurrentlyActive) { ViewCompat.setTranslationX(view, dX); ViewCompat.setTranslationY(view, dY); }