Java Code Examples for android.support.v4.view.ViewCompat#setTranslationX()

The following examples show how to use android.support.v4.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 UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public boolean animateMove(final RecyclerView.ViewHolder 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);
    }
    mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
    return true;
}
 
Example 2
Source File: VerticalItemAnimator.java    From JumpGo with Mozilla Public License 2.0 6 votes vote down vote up
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 3
Source File: ScaleInItemAnimator.java    From androidexamples with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: ClassifyItemAnimator.java    From ClassifyView with Apache License 2.0 6 votes vote down vote up
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, RecyclerView.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 5
Source File: BaseItemAnimator.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY,
    int toX, int 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 6
Source File: DefaultItemAnimator.java    From Mupdf with Apache License 2.0 6 votes vote down vote up
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder,
        int fromX, int fromY, int toX, int toY) {
    final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
    final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
    final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
    resetAnimation(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
        resetAnimation(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 7
Source File: FlipPageTransformer.java    From KUtils with Apache License 2.0 5 votes vote down vote up
@Override
public void handleLeftPage(View view, float position) {
    ViewCompat.setTranslationX(view, -view.getWidth() * position);
    float rotation = (ROTATION * position);
    ViewCompat.setRotationY(view, rotation);

    if (position > -0.5) {
        view.setVisibility(View.VISIBLE);
    } else {
        view.setVisibility(View.INVISIBLE);
    }
}
 
Example 8
Source File: ZoomCenterPageTransformer.java    From KUtils with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRightPage(View view, float position) {
    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 9
Source File: ZoomCenterPageTransformer.java    From KUtils-master with Apache License 2.0 5 votes vote down vote up
@Override
public void handleLeftPage(View view, float position) {
    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 10
Source File: ZoomStackPageTransformer.java    From KUtils with Apache License 2.0 5 votes vote down vote up
@Override
public void handleLeftPage(View view, float position) {
    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 11
Source File: ForegroundToBackgroundTransformer.java    From LoyalNativeSlider with MIT License 5 votes vote down vote up
@Override
protected void onTransform(View view, float position) {
	final float height = view.getHeight();
	final float width = view.getWidth();
	final float scale = min(position > 0 ? 1f : Math.abs(1f + position), 0.5f);

	ViewCompat.setScaleX(view, scale);
       ViewCompat.setScaleY(view,scale);
       ViewCompat.setPivotX(view,width * 0.5f);
       ViewCompat.setPivotY(view,height * 0.5f);
       ViewCompat.setTranslationX(view,position > 0 ? width * position : -width * position * 0.25f);
}
 
Example 12
Source File: ZoomCenterPageTransformer.java    From KUtils-master with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRightPage(View view, float position) {
    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 13
Source File: ViewHelper.java    From MemoryCleaner with Apache License 2.0 5 votes vote down vote up
public static void clear(View v) {
    ViewCompat.setAlpha(v, 1);
    ViewCompat.setScaleY(v, 1);
    ViewCompat.setScaleX(v, 1);
    ViewCompat.setTranslationY(v, 0);
    ViewCompat.setTranslationX(v, 0);
    ViewCompat.setRotation(v, 0);
    ViewCompat.setRotationY(v, 0);
    ViewCompat.setRotationX(v, 0);
    v.setPivotY(v.getMeasuredHeight() / 2);
    ViewCompat.setPivotX(v, v.getMeasuredWidth() / 2);
    ViewCompat.animate(v).setInterpolator(null);
}
 
Example 14
Source File: BackgroundToForegroundTransformer.java    From LoyalNativeSlider with MIT License 5 votes vote down vote up
@Override
protected void onTransform(View view, float position) {
	final float height = view.getHeight();
	final float width = view.getWidth();
	final float scale = min(position < 0 ? 1f : Math.abs(1f - position), 0.5f);

       ViewCompat.setScaleX(view, scale);
       ViewCompat.setScaleY(view,scale);
       ViewCompat.setPivotX(view,width*0.5f);
       ViewCompat.setPivotY(view,height*0.5f);
       ViewCompat.setTranslationX(view,position < 0 ? width * position : -width * position * 0.25f);
}
 
Example 15
Source File: ZoomFadePageTransformer.java    From KUtils-master with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRightPage(View view, float position) {
    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);
    ViewCompat.setAlpha(view, 1 - position);
}
 
Example 16
Source File: ItemTouchUIUtilImpl.java    From letv with Apache License 2.0 4 votes vote down vote up
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 17
Source File: FadeInLeftAnimator.java    From RecyclerviewAnimators with Apache License 2.0 4 votes vote down vote up
@Override
protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) {
    ViewCompat.setTranslationX(holder.itemView,
            -holder.itemView.getRootView().getWidth() * .25f);
    ViewCompat.setAlpha(holder.itemView, 0);
}
 
Example 18
Source File: FadePageTransformer.java    From KUtils-master with Apache License 2.0 4 votes vote down vote up
@Override
public void handleRightPage(View view, float position) {
    ViewCompat.setTranslationX(view, -view.getWidth() * position);
    ViewCompat.setAlpha(view, 1 - position);
}
 
Example 19
Source File: OvershootInLeftAnimator.java    From RecyclerviewAnimators with Apache License 2.0 4 votes vote down vote up
@Override
protected void preAnimateAddImpl(RecyclerView.ViewHolder holder) {
    ViewCompat.setTranslationX(holder.itemView, -holder.itemView.getRootView().getWidth());
}
 
Example 20
Source File: SlideItemAnimator.java    From RecyclerViewLib with Apache License 2.0 4 votes vote down vote up
@Override
protected void onAddCanceled(ViewHolder holder) {
    ViewCompat.setTranslationX(holder.itemView, 0);
}