Java Code Examples for androidx.core.view.ViewCompat#getTranslationX()

The following examples show how to use androidx.core.view.ViewCompat#getTranslationX() . 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: VerticalDividerItemDecoration.java    From UltimateRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.top = parent.getPaddingTop() +
            mMarginProvider.dividerTopMargin(position, parent) + transitionY;
    bounds.bottom = parent.getHeight() - parent.getPaddingBottom() -
            mMarginProvider.dividerBottomMargin(position, parent) + transitionY;

    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE) {
        bounds.left = child.getRight() + params.leftMargin + transitionX;
        bounds.right = bounds.left + dividerSize;
    } else {
        bounds.left = child.getRight() + params.leftMargin + dividerSize / 2 + transitionX;
        bounds.right = bounds.left;
    }

    return bounds;
}
 
Example 2
Source File: HorizontalDividerItemDecoration.java    From UltimateRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.left = parent.getPaddingLeft() +
            mMarginProvider.dividerLeftMargin(position, parent) + transitionX;
    bounds.right = parent.getWidth() - parent.getPaddingRight() -
            mMarginProvider.dividerRightMargin(position, parent) + transitionX;

    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE) {
        bounds.top = child.getBottom() + params.topMargin + transitionY;
        bounds.bottom = bounds.top + dividerSize;
    } else {
        bounds.top = child.getBottom() + params.topMargin + dividerSize / 2 + transitionY;
        bounds.bottom = bounds.top;
    }

    return bounds;
}
 
Example 3
Source File: StickyHeaderDecoration.java    From header-decor with Apache License 2.0 6 votes vote down vote up
@Nullable
public View findHeaderViewUnder(float x, float y) {
    for (RecyclerView.ViewHolder holder : headerCache.values()) {
        final View child = holder.itemView;
        final float translationX = ViewCompat.getTranslationX(child);
        final float translationY = ViewCompat.getTranslationY(child);

        if (x >= child.getLeft() + translationX &&
                x <= child.getRight() + translationX &&
                y >= child.getTop() + translationY &&
                y <= child.getBottom() + translationY) {
            return child;
        }
    }

    return null;
}
 
Example 4
Source File: DoubleHeaderDecoration.java    From header-decor with Apache License 2.0 6 votes vote down vote up
@Nullable
public View findHeaderViewUnder(float x, float y) {
    for (RecyclerView.ViewHolder holder : headerCache.values()) {
        final View child = holder.itemView;
        final float translationX = ViewCompat.getTranslationX(child);
        final float translationY = ViewCompat.getTranslationY(child);

        if (x >= child.getLeft() + translationX &&
                x <= child.getRight() + translationX &&
                y >= child.getTop() + translationY &&
                y <= child.getBottom() + translationY) {
            return child;
        }
    }

    return null;
}
 
Example 5
Source File: DoubleHeaderDecoration.java    From header-decor with Apache License 2.0 6 votes vote down vote up
@Nullable
public View findSubHeaderViewUnder(float x, float y) {
    for (RecyclerView.ViewHolder holder : subHeaderCache.values()) {
        final View child = holder.itemView;
        final float translationX = ViewCompat.getTranslationX(child);
        final float translationY = ViewCompat.getTranslationY(child);

        if (x >= child.getLeft() + translationX &&
                x <= child.getRight() + translationX &&
                y >= child.getTop() + translationY &&
                y <= child.getBottom() + translationY) {
            return child;
        }
    }

    return null;
}
 
Example 6
Source File: BaseItemAnimator.java    From recyclerview-animators 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 7
Source File: VerticalDividerItemDecoration.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.top = child.getTop() + transitionY;
    bounds.bottom = child.getBottom() + transitionY;

    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE || mDividerType == DividerType.SPACE) {
        if (alignTopEdge(parent, position)) {
            bounds.top += mMarginProvider.dividerTopMargin(position, parent);
        }
        if (alignBottomEdge(parent, position)) {
            bounds.bottom -= mMarginProvider.dividerBottomMargin(position, parent);
        }

        bounds.left = child.getRight() + params.rightMargin + transitionX;
        bounds.right = bounds.left + dividerSize;
    } else {
        // set center point of divider
        int halfSize = dividerSize / 2;
        bounds.left = child.getRight() + params.rightMargin + halfSize + transitionX;
        bounds.right = bounds.left;
    }

    if (mPositionInsideItem) {
        bounds.left -= dividerSize;
        bounds.right -= dividerSize;
    }

    return bounds;
}
 
Example 8
Source File: HorizontalDividerItemDecoration.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.left = child.getLeft() + transitionX;
    bounds.right = child.getRight() + transitionX;

    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE || mDividerType == DividerType.SPACE) {
        if (alignLeftEdge(parent, position)) {
            bounds.left += mMarginProvider.dividerLeftMargin(position, parent);
        }

        if (alignRightEdge(parent, position)) {
            bounds.right -= mMarginProvider.dividerRightMargin(position, parent);
        } else {
            // 交叉位置特殊处理
            bounds.right += getDividerSize(position, parent);
        }
        bounds.top = child.getBottom() + params.bottomMargin + transitionY;
        bounds.bottom = bounds.top + dividerSize;
    } else {
        int halfSize = dividerSize / 2;
        bounds.top = child.getBottom() + params.bottomMargin + halfSize + transitionY;
        bounds.bottom = bounds.top;
    }

    if (mPositionInsideItem) {
        bounds.top -= dividerSize;
        bounds.bottom -= dividerSize;
    }

    return bounds;
}
 
Example 9
Source File: VerticalDividerItemDecoration.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.top = child.getTop() + transitionY;
    bounds.bottom = child.getBottom() + transitionY;

    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE || mDividerType == DividerType.SPACE) {
        if (alignTopEdge(parent, position)) {
            bounds.top += mMarginProvider.dividerTopMargin(position, parent);
        }
        if (alignBottomEdge(parent, position)) {
            bounds.bottom -= mMarginProvider.dividerBottomMargin(position, parent);
        }

        bounds.left = child.getRight() + params.rightMargin + transitionX;
        bounds.right = bounds.left + dividerSize;
    } else {
        // set center point of divider
        int halfSize = dividerSize / 2;
        bounds.left = child.getRight() + params.rightMargin + halfSize + transitionX;
        bounds.right = bounds.left;
    }

    if (mPositionInsideItem) {
        bounds.left -= dividerSize;
        bounds.right -= dividerSize;
    }

    return bounds;
}
 
Example 10
Source File: HorizontalDividerItemDecoration.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.left = child.getLeft() + transitionX;
    bounds.right = child.getRight() + transitionX;

    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE || mDividerType == DividerType.SPACE) {
        if (alignLeftEdge(parent, position)) {
            bounds.left += mMarginProvider.dividerLeftMargin(position, parent);
        }

        if (alignRightEdge(parent, position)) {
            bounds.right -= mMarginProvider.dividerRightMargin(position, parent);
        } else {
            // 交叉位置特殊处理
            bounds.right += getDividerSize(position, parent);
        }
        bounds.top = child.getBottom() + params.bottomMargin + transitionY;
        bounds.bottom = bounds.top + dividerSize;
    } else {
        int halfSize = dividerSize / 2;
        bounds.top = child.getBottom() + params.bottomMargin + halfSize + transitionY;
        bounds.bottom = bounds.top;
    }

    if (mPositionInsideItem) {
        bounds.top -= dividerSize;
        bounds.bottom -= dividerSize;
    }

    return bounds;
}
 
Example 11
Source File: ItemTouchHelperExtension.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
private void getSelectedDxDy(float[] outPosition) {
    if ((mSelectedFlags & (LEFT | RIGHT)) != 0) {
        outPosition[0] = mSelectedStartX + mDx - mSelected.itemView.getLeft();
    } else {
        outPosition[0] = ViewCompat.getTranslationX(mSelected.itemView);
    }
    if ((mSelectedFlags & (UP | DOWN)) != 0) {
        outPosition[1] = mSelectedStartY + mDy - mSelected.itemView.getTop();
    } else {
        outPosition[1] = ViewCompat.getTranslationY(mSelected.itemView);
    }
}
 
Example 12
Source File: BaseItemAnimator.java    From recyclerview-animators with Apache License 2.0 5 votes vote down vote up
@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;
}