Java Code Examples for androidx.recyclerview.widget.RecyclerView#getHeight()

The following examples show how to use androidx.recyclerview.widget.RecyclerView#getHeight() . 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: DividerItemDecoration.java    From libcommon with Apache License 2.0 6 votes vote down vote up
protected void drawHorizontal(final Canvas canvas, final RecyclerView parent) {
	final RecyclerView.LayoutManager manager = parent.getLayoutManager();

	final int top = parent.getPaddingTop();
	final int bottom = parent.getHeight() - parent.getPaddingBottom();

	final int childCount = parent.getChildCount() - 1;
	for (int i = 0; i < childCount; i++) {
		final View child = parent.getChildAt(i);
		if (hasDivider(child)) {
			final int left = child.getLeft();
			final int right = left + mDivider.getIntrinsicWidth();
			mDivider.setBounds(left, top, right, bottom);
			mDivider.draw(canvas);
		}
	}
}
 
Example 3
Source File: CustomDividerItemDecoration.java    From Android-skin-support with MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int top;
    final int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top,
                parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(ViewCompat.getTranslationX(child));
        final int left = right - mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 4
Source File: ScalingScrollLayoutCallback.java    From user-interface-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onLayoutFinished(View child, RecyclerView parent) {

    // Figure out % progress from top to bottom.
    float centerOffset = ((float) child.getHeight() / 2.0f) /  (float) parent.getHeight();
    float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset;

    // Normalizes for center.
    mProgressToCenter = Math.abs(0.5f - yRelativeToCenterOffset);

    // Adjusts to the maximum scale.
    mProgressToCenter = Math.min(mProgressToCenter, MAX_CHILD_SCALE);

    child.setScaleX(1 - mProgressToCenter);
    child.setScaleY(1 - mProgressToCenter);
}
 
Example 5
Source File: DividerItemDecorationEx.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 6 votes vote down vote up
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    int top;
    int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top, parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    int childCount = parent.getChildCount();

    for (int i = 0; i < childCount; ++i) {
        View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        int right = mBounds.right + Math.round(child.getTranslationX());
        int left = right - mDivider.getIntrinsicWidth();
        this.mDivider.setBounds(left, top, right, bottom);
        this.mDivider.draw(canvas);
    }

    canvas.restore();
}
 
Example 6
Source File: DividerItemDecoration.java    From EnhancedScreenshotNotification with GNU General Public License v3.0 6 votes vote down vote up
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int top;
    final int bottom;
    if (parent.getClipToPadding()) {
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
        canvas.clipRect(parent.getPaddingLeft(), top,
                parent.getWidth() - parent.getPaddingRight(), bottom);
    } else {
        top = 0;
        bottom = parent.getHeight();
    }

    final int childCount = parent.getChildCount() - (doNotDrawForLastItem ? 1 : 0);
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds);
        final int right = mBounds.right + Math.round(child.getTranslationX());
        final int left = right - mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 7
Source File: DividerItemDecoration.java    From RecyclerViewExtensions with MIT License 6 votes vote down vote up
public void drawHorizontal(Canvas canvas, RecyclerView parent) {
    int top = parent.getPaddingTop();
    int bottom = parent.getHeight() - parent.getPaddingBottom();

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);
        if (!hasDivider(parent, child)) {
            continue;
        }

        if (mDrawable.isStateful()) {
            mDrawable.setState(child.getDrawableState());
        }

        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        int left = child.getRight() + params.rightMargin + Math.round(child.getTranslationX());
        int right = left + mDrawable.getIntrinsicWidth();
        drawDivider(canvas, left, top, right, bottom, child.getAlpha());
    }
}
 
Example 8
Source File: DividerItemDecoration.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int left = child.getRight() + params.rightMargin;
        final int right = left + divider.getIntrinsicHeight();
        divider.setBounds(left, top, right, bottom);
        divider.draw(c);
    }
}
 
Example 9
Source File: DividerItemDecoration.java    From FChat with MIT License 5 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();
 
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 10
Source File: ItemTouchHelperExtension.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
/**
 * Called when {@link #onMove(RecyclerView, ViewHolder, ViewHolder)} returns true.
 * <p>
 * ItemTouchHelper does not create an extra Bitmap or View while dragging, instead, it
 * modifies the existing View. Because of this reason, it is important that the View is
 * still part of the layout after it is moved. This may not work as intended when swapped
 * Views are close to RecyclerView bounds or there are gaps between them (e.g. other Views
 * which were not eligible for dropping over).
 * <p>
 * This method is responsible to give necessary hint to the LayoutManager so that it will
 * keep the View in visible area. For example, for LinearLayoutManager, this is as simple
 * <p>
 * <p>
 * Default implementation calls {@link RecyclerView#scrollToPosition(int)} if the View's
 * new position is likely to be out of bounds.
 * <p>
 * It is important to ensure the ViewHolder will stay visible as otherwise, it might be
 * removed by the LayoutManager if the move causes the View to go out of bounds. In that
 * case, drag will end prematurely.
 *
 * @param recyclerView The RecyclerView controlled by the ItemTouchHelper.
 * @param viewHolder   The ViewHolder under user's control.
 * @param fromPos      The previous adapter position of the dragged item (before it was
 *                     moved).
 * @param target       The ViewHolder on which the currently active item has been dropped.
 * @param toPos        The new adapter position of the dragged item.
 * @param x            The updated left value of the dragged View after drag translations
 *                     are applied. This value does not include margins added by
 *                     {@link RecyclerView.ItemDecoration}s.
 * @param y            The updated top value of the dragged View after drag translations
 *                     are applied. This value does not include margins added by
 *                     {@link RecyclerView.ItemDecoration}s.
 */
public void onMoved(final RecyclerView recyclerView,
                    final ViewHolder viewHolder, int fromPos, final ViewHolder target, int toPos, int x,
                    int y) {
    final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof ViewDropHandler) {
        ((ViewDropHandler) layoutManager).prepareForDrop(viewHolder.itemView,
                target.itemView, x, y);
        return;
    }

    // if layout manager cannot handle it, do some guesswork
    if (layoutManager.canScrollHorizontally()) {
        final int minLeft = layoutManager.getDecoratedLeft(target.itemView);
        if (minLeft <= recyclerView.getPaddingLeft()) {
            recyclerView.scrollToPosition(toPos);
        }
        final int maxRight = layoutManager.getDecoratedRight(target.itemView);
        if (maxRight >= recyclerView.getWidth() - recyclerView.getPaddingRight()) {
            recyclerView.scrollToPosition(toPos);
        }
    }

    if (layoutManager.canScrollVertically()) {
        final int minTop = layoutManager.getDecoratedTop(target.itemView);
        if (minTop <= recyclerView.getPaddingTop()) {
            recyclerView.scrollToPosition(toPos);
        }
        final int maxBottom = layoutManager.getDecoratedBottom(target.itemView);
        if (maxBottom >= recyclerView.getHeight() - recyclerView.getPaddingBottom()) {
            recyclerView.scrollToPosition(toPos);
        }
    }
}
 
Example 11
Source File: RecyclerCollectionEventsController.java    From litho with Apache License 2.0 5 votes vote down vote up
private int getSmoothScrollTarget(boolean forward, int defaultTarget) {
  switch (mSnapMode) {
    case SNAP_NONE:
      return defaultTarget;
    case SNAP_TO_START:
      return Math.max(
          0,
          forward
              ? mFirstCompletelyVisibleItemPosition + 1
              : mFirstCompletelyVisibleItemPosition - 1);
    case SNAP_TO_END: // SNAP_TO_END not yet implemented
      return Math.max(
          0,
          forward
              ? mLastCompletelyVisibleItemPosition + 1
              : mLastCompletelyVisibleItemPosition - 1);
    case SNAP_TO_CENTER:
    case SNAP_TO_CENTER_CHILD:
      final RecyclerView recyclerView = getRecyclerView();
      if (recyclerView == null) {
        return defaultTarget;
      }
      final int centerPositionX = recyclerView.getWidth() / 2;
      final int centerPositionY = recyclerView.getHeight() / 2;
      final View centerView = recyclerView.findChildViewUnder(centerPositionX, centerPositionY);
      if (centerView == null) {
        return defaultTarget;
      }
      final int centerViewPosition = recyclerView.getChildAdapterPosition(centerView);
      return Math.max(0, forward ? centerViewPosition + 1 : centerViewPosition - 1);
    default:
      return defaultTarget;
  }
}
 
Example 12
Source File: HorizonRecyclerDivider.java    From sa-sdk-android with Apache License 2.0 5 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 13
Source File: DividerItemDecoration.java    From android-test with Apache License 2.0 5 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 14
Source File: DividerItemDecoration.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 15
Source File: InsetDecoration.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    int top = 0;
    int left = 0;
    int right = parent.getWidth();
    int bottom = parent.getHeight();

    if (mGravity == Gravity.TOP) {
        mInset.setBounds(left, top, right, mHeight);
    } else if (mGravity == Gravity.BOTTOM) {
        mInset.setBounds(left, bottom - mHeight, right, bottom);
    }

    mInset.draw(c);
}
 
Example 16
Source File: WeSwipeHelper.java    From monero-wallet-android-app with MIT License 5 votes vote down vote up
/**
 * Called when {@link #onMove(RecyclerView, RecyclerView.ViewHolder, RecyclerView.ViewHolder)} returns true.
 * <p>
 * WeSwipeHelper does not create an extra Bitmap or View while dragging, instead, it
 * modifies the existing View. Because of this reason, it is important that the View is
 * still part of the layout after it is moved. This may not work as intended when swapped
 * Views are close to RecyclerView bounds or there are gaps between them (e.g. other Views
 * which were not eligible for dropping over).
 * <p>
 * This method is responsible to give necessary hint to the LayoutManager so that it will
 * keep the View in visible area. For example, for LinearLayoutManager, this is as simple
 * as calling {@link LinearLayoutManager#scrollToPositionWithOffset(int, int)}.
 * <p>
 * Default implementation calls {@link RecyclerView#scrollToPosition(int)} if the View's
 * new position is likely to be out of bounds.
 * <p>
 * It is important to ensure the ViewHolder will stay visible as otherwise, it might be
 * removed by the LayoutManager if the move causes the View to go out of bounds. In that
 * case, drag will end prematurely.
 *
 * @param recyclerView The RecyclerView controlled by the WeSwipeHelper.
 * @param viewHolder   The ViewHolder under user's control.
 * @param fromPos      The previous adapter position of the dragged item (before it was
 *                     moved).
 * @param target       The ViewHolder on which the currently active item has been dropped.
 * @param toPos        The new adapter position of the dragged item.
 * @param x            The updated left value of the dragged View after drag translations
 *                     are applied. This value does not include margins added by
 *                     {@link RecyclerView.ItemDecoration}s.
 * @param y            The updated top value of the dragged View after drag translations
 *                     are applied. This value does not include margins added by
 *                     {@link RecyclerView.ItemDecoration}s.
 */
public void onMoved(final RecyclerView recyclerView,
                    final RecyclerView.ViewHolder viewHolder, int fromPos, final RecyclerView.ViewHolder target, int toPos, int x,
                    int y) {
    final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof WeSwipeHelper.ViewDropHandler) {
        ((WeSwipeHelper.ViewDropHandler) layoutManager).prepareForDrop(viewHolder.itemView,
                target.itemView, x, y);
        return;
    }

    // if layout manager cannot handle it, do some guesswork
    if (layoutManager.canScrollHorizontally()) {
        final int minLeft = layoutManager.getDecoratedLeft(target.itemView);
        if (minLeft <= recyclerView.getPaddingLeft()) {
            recyclerView.scrollToPosition(toPos);
        }
        final int maxRight = layoutManager.getDecoratedRight(target.itemView);
        if (maxRight >= recyclerView.getWidth() - recyclerView.getPaddingRight()) {
            recyclerView.scrollToPosition(toPos);
        }
    }

    if (layoutManager.canScrollVertically()) {
        final int minTop = layoutManager.getDecoratedTop(target.itemView);
        if (minTop <= recyclerView.getPaddingTop()) {
            recyclerView.scrollToPosition(toPos);
        }
        final int maxBottom = layoutManager.getDecoratedBottom(target.itemView);
        if (maxBottom >= recyclerView.getHeight() - recyclerView.getPaddingBottom()) {
            recyclerView.scrollToPosition(toPos);
        }
    }
}
 
Example 17
Source File: DividerItemDecoration.java    From a with GNU General Public License v3.0 5 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mDrawable.getIntrinsicHeight();
        mDrawable.setBounds(left, top, right, bottom);
        mDrawable.draw(c);
    }
}
 
Example 18
Source File: StickyHeaderDecoration.java    From GetApk with MIT License 4 votes vote down vote up
protected void createPinnedHeader(RecyclerView parent) {
    updateStickyHeader(parent);

    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager == null || layoutManager.getChildCount() <= 0) {
        return;
    }
    int firstVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
    int firstCompletelyVisiblePosition = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
    int headerPosition = findStickyHeaderPosition(parent, firstVisiblePosition);
    if (headerPosition == -1 || (headerPosition == firstCompletelyVisiblePosition)) {
        resetPinnedHeader();
        return;
    }
    if (headerPosition >= 0 && mHeaderPosition != headerPosition) {
        mHeaderPosition = headerPosition;
        int viewType = mAdapter.getItemViewType(headerPosition);
        mCurrentItemType = viewType;

        RecyclerView.ViewHolder stickyViewHolder = mAdapter.createViewHolder(parent, viewType);
        if (mAdapter instanceof SwipeStickyAdapter) {
            ((SwipeStickyAdapter) mAdapter).onBindSwipeViewHolder(stickyViewHolder, headerPosition);
        } else {
            mAdapter.onBindViewHolder(stickyViewHolder, headerPosition);
        }

        mStickyView = stickyViewHolder.itemView;


        // read layout parameters
        ViewGroup.LayoutParams layoutParams = mStickyView.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            mStickyView.setLayoutParams(layoutParams);
        }

        int heightMode = View.MeasureSpec.getMode(layoutParams.height);
        int heightSize = View.MeasureSpec.getSize(layoutParams.height);

        if (heightMode == View.MeasureSpec.UNSPECIFIED) {
            heightMode = View.MeasureSpec.EXACTLY;
        }

        int maxHeight = parent.getHeight() - parent.getPaddingTop() - parent.getPaddingBottom();
        if (heightSize > maxHeight) {
            heightSize = maxHeight;
        }

        // measure & layout
        int ws = View.MeasureSpec.makeMeasureSpec(parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight(), View.MeasureSpec.EXACTLY);
        int hs = View.MeasureSpec.makeMeasureSpec(heightSize, heightMode);
        mStickyView.measure(ws, hs);
        mStickyView.layout(0, 0, mStickyView.getMeasuredWidth(), mStickyView.getMeasuredHeight());
    }
}
 
Example 19
Source File: OrientationStateVerticalLeft.java    From LoopBar with MIT License 4 votes vote down vote up
@Override
public boolean isItemsFitOnScreen(RecyclerView container, int itemsSize) {
    calcItemHeight(container);
    return container.getHeight() >= itemHeight * (itemsSize);
}
 
Example 20
Source File: ItemTouchHelper.java    From Carbon with Apache License 2.0 3 votes vote down vote up
/**
 * Called when {@link #onMove(RecyclerView, ViewHolder, ViewHolder)} returns true.
 * <p>
 * ItemTouchHelper does not create an extra Bitmap or View while dragging, instead, it
 * modifies the existing View. Because of this reason, it is important that the View is
 * still part of the layout after it is moved. This may not work as intended when swapped
 * Views are close to RecyclerView bounds or there are gaps between them (e.g. other Views
 * which were not eligible for dropping over).
 * <p>
 * This method is responsible to give necessary hint to the LayoutManager so that it will
 * keep the View in visible area. For example, for LinearLayoutManager, this is as simple as
 * calling {@link LinearLayoutManager#scrollToPositionWithOffset(int, int)}.
 * <p>
 * Default implementation calls {@link RecyclerView#scrollToPosition(int)} if the View's new
 * position is likely to be out of bounds.
 * <p>
 * It is important to ensure the ViewHolder will stay visible as otherwise, it might be
 * removed by the LayoutManager if the move causes the View to go out of bounds. In that
 * case, drag will end prematurely.
 *
 * @param recyclerView The RecyclerView controlled by the ItemTouchHelper.
 * @param viewHolder   The ViewHolder under user's control.
 * @param fromPos      The previous adapter position of the dragged item (before it was
 *                     moved).
 * @param target       The ViewHolder on which the currently active item has been dropped.
 * @param toPos        The new adapter position of the dragged item.
 * @param x            The updated left value of the dragged View after drag translations
 *                     are applied. This value does not include margins added by {@link
 *                     RecyclerView.ItemDecoration}s.
 * @param y            The updated top value of the dragged View after drag translations are
 *                     applied. This value does not include margins added by {@link
 *                     RecyclerView.ItemDecoration}s.
 */
public void onMoved(final RecyclerView recyclerView,
                    final ViewHolder viewHolder, int fromPos, final ViewHolder target, int toPos, int x,
                    int y) {
    final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof ViewDropHandler) {
        ((ViewDropHandler) layoutManager).prepareForDrop(viewHolder.itemView,
                target.itemView, x, y);
        return;
    }
    // if layout manager cannot handle it, do some guesswork
    if (layoutManager.canScrollHorizontally()) {
        final int minLeft = layoutManager.getDecoratedLeft(target.itemView);
        if (minLeft <= recyclerView.getPaddingLeft()) {
            recyclerView.scrollToPosition(toPos);
        }
        final int maxRight = layoutManager.getDecoratedRight(target.itemView);
        if (maxRight >= recyclerView.getWidth() - recyclerView.getPaddingRight()) {
            recyclerView.scrollToPosition(toPos);
        }
    }
    if (layoutManager.canScrollVertically()) {
        final int minTop = layoutManager.getDecoratedTop(target.itemView);
        if (minTop <= recyclerView.getPaddingTop()) {
            recyclerView.scrollToPosition(toPos);
        }
        final int maxBottom = layoutManager.getDecoratedBottom(target.itemView);
        if (maxBottom >= recyclerView.getHeight() - recyclerView.getPaddingBottom()) {
            recyclerView.scrollToPosition(toPos);
        }
    }
}