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

The following examples show how to use androidx.recyclerview.widget.RecyclerView#getPaddingRight() . 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: DividerItemDecorator.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    int dividerLeft = parent.getPaddingLeft();
    int dividerRight = parent.getWidth() - parent.getPaddingRight();

    int childCount = parent.getChildCount();
    for (int i = 0; i <= childCount - 2; i++) {
        View child = parent.getChildAt(i);

        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

        int dividerTop = child.getBottom() + params.bottomMargin;
        int dividerBottom = dividerTop + mDivider.getIntrinsicHeight();

        mDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom);
        mDivider.draw(canvas);
    }
}
 
Example 2
Source File: ResultItemDecoration.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {

  int left = parent.getPaddingLeft();
  int right = parent.getWidth() - parent.getPaddingRight();

  int childCount = parent.getChildCount();

  for (int i = 0; i < childCount; i++) {

    View child = parent.getChildAt(i);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

    int top = child.getBottom() + params.bottomMargin;
    int bottom = top + divider.getIntrinsicHeight();

    divider.setBounds(left, top, right, bottom);
    divider.draw(canvas);
  }
}
 
Example 3
Source File: RcvLinearDecoration.java    From RecyclerViewAdapter with Apache License 2.0 6 votes vote down vote up
private void drawVertical(Canvas c, RecyclerView parent)
{
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    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 top = child.getBottom() + params.bottomMargin;
        final int bottom = top + mDividerSize;
        if (mDividerDrawable != null)
        {
            mDividerDrawable.setBounds(left, top, right, bottom);
            mDividerDrawable.draw(c);
        } else if (mDividerPaint != null)
        {
            c.drawRect(left, top, right, bottom, mDividerPaint);
        }
    }
}
 
Example 4
Source File: SimpleDivider.java    From hipda with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);

        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

        int top = child.getBottom() + params.bottomMargin;
        int bottom = top + mDivider.getIntrinsicHeight();

        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 5
Source File: FromRecyclerViewListener.java    From GestureViews with Apache License 2.0 6 votes vote down vote up
@Override
void scrollToPosition(RecyclerView list, int pos) {
    if (list.getLayoutManager() instanceof LinearLayoutManager) {
        // Centering item in its parent
        final LinearLayoutManager manager = (LinearLayoutManager) list.getLayoutManager();
        final boolean isHorizontal = manager.getOrientation() == LinearLayoutManager.HORIZONTAL;

        int offset = isHorizontal
                ? (list.getWidth() - list.getPaddingLeft() - list.getPaddingRight()) / 2
                : (list.getHeight() - list.getPaddingTop() - list.getPaddingBottom()) / 2;

        final RecyclerView.ViewHolder holder = list.findViewHolderForAdapterPosition(pos);
        if (holder != null) {
            final View view = holder.itemView;
            offset -= isHorizontal ? view.getWidth() / 2 : view.getHeight() / 2;
        }

        manager.scrollToPositionWithOffset(pos, offset);
    } else {
        list.scrollToPosition(pos);
    }
}
 
Example 6
Source File: SimpleDividerItemDecoration.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    canvas.save();
    final int right;
    //noinspection AndroidLintNewApi - NewApi lint fails to handle overrides.
    if (parent.getClipToPadding()) {
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(leftPadding, parent.getPaddingTop(), right,
                parent.getHeight() - parent.getPaddingBottom());
    } else {
        right = parent.getWidth();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, bounds);
        final int bottom = bounds.bottom + Math.round(child.getTranslationY());
        final int top = bottom - 1;
        divider.setBounds(leftPadding, top, right, bottom);
        divider.draw(canvas);
    }
    canvas.restore();
}
 
Example 7
Source File: GroupItemDecoration.java    From CalendarView with Apache License 2.0 6 votes vote down vote up
/**
 * 绘制分组Group
 *
 * @param c      Canvas
 * @param parent RecyclerView
 */
protected void onDrawGroup(Canvas c, RecyclerView parent) {
    int paddingLeft = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();
    int top, bottom;
    int count = parent.getChildCount();
    for (int i = 0; i < parent.getChildCount(); i++) {
        View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        int key = params.getViewLayoutPosition();
        if (mGroup.containsKey(key)) {
            top = child.getTop() - params.topMargin - mGroupHeight;
            bottom = top + mGroupHeight;
            c.drawRect(paddingLeft, top, right, bottom, mBackgroundPaint);
            String group = mGroup.get(params.getViewLayoutPosition()).toString();
            float x;
            float y = top + mTextBaseLine;
            if (isCenter) {
                x = parent.getMeasuredWidth() / 2 - getTextX(group);
            } else {
                x = mPaddingLeft;
            }
            c.drawText(group, x, y, mTextPaint);
        }
    }
}
 
Example 8
Source File: GridSpacingItemDecoration.java    From a with GNU General Public License v3.0 6 votes vote down vote up
private void drawHorizontal(Canvas canvas, RecyclerView parent) {
    int left = parent.getPaddingLeft();
    int right = parent.getMeasuredWidth() - parent.getPaddingRight();
    final int childSize = parent.getChildCount();
    for (int i = 0; i < childSize; i++) {
        final View child = parent.getChildAt(i);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
        int top = child.getBottom() + layoutParams.bottomMargin;
        int bottom = top + space;
        if (mDivider != null) {
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(canvas);
        }
        if (mPaint != null) {
            canvas.drawRect(left, top, right, bottom, mPaint);
        }

    }
}
 
Example 9
Source File: AutoColumnGridLayoutManager.java    From RecyclerExt with Apache License 2.0 6 votes vote down vote up
/**
 * Performs the actual calculation for determining the number of possible
 * columns by using the {@link #maxColumnCount}, {@link #minColumnSpacingEdge}, and
 * {@link #minColumnSpacingSeparator} in conjunction with the requested width
 * for the items
 *
 * @param recyclerView The RecyclerView to use when determining the possible number of columns
 * @param gridItemWidth The requested width for items to be
 * @return The calculated number of possible columns
 */
protected int getColumnCount(@NonNull RecyclerView recyclerView, int gridItemWidth) {
    int padding = recyclerView.getPaddingLeft() + recyclerView.getPaddingRight();
    int usableWidth = recyclerView.getWidth() - padding;

    int columnCount = Math.min(usableWidth / gridItemWidth, maxColumnCount);
    int usedColumnWidth, minRequiredSpacing;

    //Decreases the columnCount until the specified min spacing can be achieved.
    do {
        usedColumnWidth = columnCount * gridItemWidth;
        minRequiredSpacing = (2 * minColumnSpacingEdge) + ((columnCount -1) * minColumnSpacingSeparator);

        //If the specified min spacing is reached, return the number of columns
        if (usableWidth - usedColumnWidth - minRequiredSpacing >= 0) {
            return columnCount;
        }

        columnCount--;
    } while(columnCount > 1);

    return columnCount;
}
 
Example 10
Source File: DividerItemDecorationUtils.java    From shinny-futures-android with GNU General Public License v3.0 5 votes vote down vote up
private void drawVertical(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();
    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 top = child.getBottom() + params.bottomMargin;
        final int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 11
Source File: DividerItemDecoration.java    From FChat with MIT License 5 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();
 
    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 top = child.getBottom() + params.bottomMargin;
        final int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 12
Source File: DividerItemDecoration.java    From monero-wallet-android-app with MIT License 5 votes vote down vote up
private void drawVertical(Canvas canvas, RecyclerView parent) {
    canvas.save();
    final int left;
    final int right;
    //noinspection AndroidLintNewApi - NewApi lint fails to handle overrides.
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right,
                parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int bottom = mBounds.bottom + Math.round(child.getTranslationY());
        final int top = bottom - mDividerSize;
        mDividerPaint.setColor(mDividerColor);
        mDividerPaint.setStyle(Paint.Style.FILL);
        canvas.drawRect(left + mMarginStart, top + mMarginTop, right - mMarginEnd, bottom - mMarginBottom, mDividerPaint);
    }
    canvas.restore();
}
 
Example 13
Source File: AdvancedDividerItemDecoration.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    canvas.save();
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        canvas.clipRect(left, parent.getPaddingTop(), right,
                parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        if (!hasDivider(parent, child))
            continue;
        parent.getDecoratedBoundsWithMargins(child, mBounds);
        final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child));
        final int top = bottom - mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.setAlpha((int) (child.getAlpha() * 255));
        mDivider.draw(canvas);
    }
    canvas.restore();
}
 
Example 14
Source File: MyListDivider.java    From Ruisi with Apache License 2.0 5 votes vote down vote up
public void drawHorizontalLine(Canvas c, RecyclerView parent, RecyclerView.State state) {
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount - 1; i++) {
        final View child = parent.getChildAt(i);
        //获得child的布局信息
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int top = child.getBottom() + params.bottomMargin;
        final int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left + SIZE_PADDING, top, right - SIZE_PADDING, bottom);
        mDivider.draw(c);
    }
}
 
Example 15
Source File: ListRecyclerView.java    From NekoSMS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams)child.getLayoutParams();
        int top = child.getBottom() + params.bottomMargin + (int)child.getTranslationY();
        int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example 16
Source File: EventItemDecorator.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (parent.getLayoutManager() == null) {
        return;
    }

    c.save();
    final int left;
    final int right;
    if (parent.getClipToPadding()) {
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
        c.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom());
    } else {
        left = 0;
        right = parent.getWidth();
    }

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        parent.getDecoratedBoundsWithMargins(child, bounds);

        int position = parent.getChildAdapterPosition(child);
        if (parent.getAdapter().getItemViewType(position) == EventListAdapter.ITEM_TYPE_HEADER ||
            parent.getAdapter().getItemViewType(position + 1) == EventListAdapter.ITEM_TYPE_HEADER ||
            position == state.getItemCount() - 1) {
            continue;
        }

        final int bottom = bounds.bottom + Math.round(ViewCompat.getTranslationY(child));
        final int top = bottom - divider.getIntrinsicHeight();
        divider.setBounds(left, top, right, bottom);
        divider.draw(c);
    }
    c.restore();
}
 
Example 17
Source File: AssemblyRecyclerLinerDivider.java    From assembly-adapter with Apache License 2.0 5 votes vote down vote up
private void drawVertical(Canvas c, RecyclerView parent) {
    int firstDataItemPosition = 0;
    int lastDataItemPosition = 0;
    RecyclerView.Adapter adapter = recyclerView.getAdapter();
    AssemblyRecyclerAdapter recyclerAdapter = null;
    if (adapter instanceof AssemblyRecyclerAdapter) {
        recyclerAdapter = (AssemblyRecyclerAdapter) adapter;
        firstDataItemPosition = recyclerAdapter.getHeaderCount();
        lastDataItemPosition = firstDataItemPosition + (recyclerAdapter.getDataCount() - 1);
    }

    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        int itemPosition = ((RecyclerView.LayoutParams) child.getLayoutParams()).getViewLayoutPosition();
        int bottomMargin = ((RecyclerView.LayoutParams) child.getLayoutParams()).bottomMargin;

        if (recyclerAdapter == null || (itemPosition >= firstDataItemPosition && itemPosition <= lastDataItemPosition)) {
            final int top = child.getBottom() + bottomMargin;
            final int bottom = top + mDivider.getIntrinsicHeight();
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(c);
        }
    }
}
 
Example 18
Source File: DividerItemDecoration.java    From RvHelper with Apache License 2.0 5 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent) {

        final int left = parent.getPaddingLeft();
        final int right = parent.getWidth() - parent.getPaddingRight();

        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 top = child.getBottom() + params.bottomMargin;
            final int bottom = top + mDivider.getIntrinsicHeight();
            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(c);
        }
    }
 
Example 19
Source File: AutoColumnGridLayoutManager.java    From RecyclerExt with Apache License 2.0 4 votes vote down vote up
/**
 * Calculates and adds the amount of spacing that needs to be between each
 * column, row, and the edges of the RecyclerView.  This pays attention to
 * the value from {@link #setSpacingMethod(SpacingMethod)}
 *
 * @param recyclerView The RecyclerView to use for determining the amount of space that needs to be added
 * @param gridItemWidth The requested width for the items
 * @param columnCount The number of columns to display
 */
protected void updateSpacing(@NonNull RecyclerView recyclerView, int gridItemWidth, int columnCount) {
    //Sets the decoration for the calculated spacing
    if (spacerDecoration == null) {
        spacerDecoration = new SpacerDecoration();
        spacerDecoration.setAllowedEdgeSpacing(SpacerDecoration.EDGE_SPACING_LEFT | SpacerDecoration.EDGE_SPACING_RIGHT);
        recyclerView.addItemDecoration(spacerDecoration);
    }

    edgeSpacing = minColumnSpacingEdge;
    int separatorSpacing = minColumnSpacingSeparator / 2;


    //Calculates the edge spacing requirements
    int padding = recyclerView.getPaddingLeft() + recyclerView.getPaddingRight();
    int usableWidth = recyclerView.getWidth() - padding;

    int separatorCount = columnCount -1;
    int spacerCount = 2 * columnCount;

    int freeSpace = usableWidth - (gridItemWidth * columnCount);
    int extraSpace = freeSpace - (2 * minColumnSpacingEdge) - (separatorCount * minColumnSpacingSeparator);

    //If we can add spacing, then we need to calculate how much and where to add it
    if (extraSpace >= spacerCount) {
        if (spacingMethod == SpacingMethod.ALL) {
            int totalMinEdges = minColumnSpacingEdge * 2;
            int totalMinSeparators = separatorCount * minColumnSpacingSeparator;

            //If the totalMinSpace is 0, then the percentage is edge count / separators + edges
            int totalMinSpace = totalMinEdges + totalMinSeparators;
            double edgeSpacePercentage = totalMinSpace == 0 ? (2 / (2 + separatorCount)) : (double)totalMinEdges / (double)totalMinSpace;
            int totalSeparatorSpace = (int)((1d - edgeSpacePercentage) * freeSpace);

            separatorSpacing = spacerCount == 0 ? 0 : totalSeparatorSpace / spacerCount;
            edgeSpacing = ((freeSpace - totalSeparatorSpace) / 2) + separatorSpacing;
        } else if (spacingMethod == SpacingMethod.EDGES) {
            edgeSpacing = (freeSpace - (separatorSpacing * spacerCount)) / 2;
        } else { //SEPARATOR
            separatorSpacing = spacerCount == 0 ? 0 : freeSpace / spacerCount;
        }

        edgeSpacing -= separatorSpacing;
    }

    //Updates the spacing using the decoration and padding
    recyclerView.setPadding(
            recyclerView.getPaddingLeft() + edgeSpacing,
            recyclerView.getPaddingTop(),
            recyclerView.getPaddingRight() + edgeSpacing,
            recyclerView.getPaddingBottom()
    );

    spacerDecoration.update(separatorSpacing, matchSpacing ? separatorSpacing : rowSpacing / 2);
}
 
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);
        }
    }
}