Java Code Examples for androidx.recyclerview.widget.RecyclerView#getPaddingBottom()
The following examples show how to use
androidx.recyclerview.widget.RecyclerView#getPaddingBottom() .
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: DividerItemDecoration.java From WidgetCase with Apache License 2.0 | 6 votes |
private void drawHorizontal(Canvas canvas, RecyclerView parent) { canvas.save(); final int top; final int bottom; //noinspection AndroidLintNewApi - NewApi lint fails to handle overrides. 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 - 1; 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 2
Source File: DividerItemDecorationEx.java From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 | 6 votes |
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 3
Source File: DividerItemDecoration.java From RecyclerViewExtensions with MIT License | 6 votes |
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 4
Source File: VerticalDividerItemDecoration.java From UltimateRecyclerView with Apache License 2.0 | 6 votes |
@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 5
Source File: DividerItemDecoration.java From libcommon with Apache License 2.0 | 6 votes |
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 6
Source File: InstallerXAdapterDividerItemDecoration.java From SAI with GNU General Public License v3.0 | 6 votes |
private void drawHorizontal(Canvas canvas, RecyclerView parent) { canvas.save(); final int top; final int bottom; //noinspection AndroidLintNewApi - NewApi lint fails to handle overrides. 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(child.getTranslationX()); final int left = right - mDivider.getIntrinsicWidth(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(canvas); } canvas.restore(); }
Example 7
Source File: CustomDividerItemDecoration.java From Android-skin-support with MIT License | 6 votes |
@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 8
Source File: GridSpacingItemDecoration.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
private void drawVertical(Canvas canvas, RecyclerView parent) { final int top = parent.getPaddingTop(); final int bottom = parent.getMeasuredHeight() - parent.getPaddingBottom(); 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(); final int left = child.getRight() + layoutParams.rightMargin; final int right = left + 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: DividerItemDecoration.java From a with GNU General Public License v3.0 | 5 votes |
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 10
Source File: AssemblyRecyclerLinerDivider.java From assembly-adapter with Apache License 2.0 | 5 votes |
private void drawHorizontal(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 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); int itemPosition = ((RecyclerView.LayoutParams) child.getLayoutParams()).getViewLayoutPosition(); int rightMargin = ((RecyclerView.LayoutParams) child.getLayoutParams()).rightMargin; if (recyclerAdapter == null || (itemPosition >= firstDataItemPosition && itemPosition <= lastDataItemPosition)) { final int left = child.getRight() + rightMargin; final int right = left + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } } }
Example 11
Source File: DividerItemDecoration.java From RvHelper with Apache License 2.0 | 5 votes |
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 12
Source File: MyListDivider.java From Ruisi with Apache License 2.0 | 5 votes |
public void drawVerticalLine(Canvas c, RecyclerView parent, RecyclerView.State state) { int top = parent.getPaddingTop(); int bottom = parent.getHeight() - parent.getPaddingBottom(); 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 left = child.getRight() + params.rightMargin; final int right = left + mDivider.getIntrinsicWidth(); mDivider.setBounds(left, top + SIZE_PADDING, right, bottom - SIZE_PADDING); mDivider.draw(c); } }
Example 13
Source File: DividerItemDecoration.java From FChat with MIT License | 5 votes |
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: ItemTouchHelperExtension.java From CrazyDaily with Apache License 2.0 | 5 votes |
/** * 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 15
Source File: FlexibleItemDecoration.java From FlexibleAdapter with Apache License 2.0 | 5 votes |
@SuppressLint("NewApi") protected 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 itemCount = parent.getChildCount(); for (int i = 0; i < itemCount - mDividerOnLastItem; i++) { final View child = parent.getChildAt(i); RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child); if (shouldDrawDivider(viewHolder)) { 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 16
Source File: DividerItemDecorationUtils.java From shinny-futures-android with GNU General Public License v3.0 | 5 votes |
private 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 17
Source File: WeSwipeHelper.java From monero-wallet-android-app with MIT License | 5 votes |
/** * 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 18
Source File: StickyHeaderDecoration.java From GetApk with MIT License | 4 votes |
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: MediaActivity.java From Telegram with GNU General Public License v2.0 | 4 votes |
private void updateSections(RecyclerView listView, boolean checkTopBottom) { int count = listView.getChildCount(); int minPositionDateHolder = Integer.MAX_VALUE; View minDateChild = null; float padding = listView.getPaddingTop() + actionBar.getTranslationY(); int minTop = Integer.MAX_VALUE; int maxBottom = 0; for (int a = 0; a < count; a++) { View view = listView.getChildAt(a); int bottom = view.getBottom(); minTop = Math.min(minTop, view.getTop()); maxBottom = Math.max(bottom, maxBottom); if (bottom <= padding) { continue; } int position = view.getBottom(); if (view instanceof SharedMediaSectionCell || view instanceof GraySectionCell) { if (view.getAlpha() != 1.0f) { view.setAlpha(1.0f); } if (position < minPositionDateHolder) { minPositionDateHolder = position; minDateChild = view; } } } if (minDateChild != null) { if (minDateChild.getTop() > padding) { if (minDateChild.getAlpha() != 1.0f) { minDateChild.setAlpha(1.0f); } } else { if (minDateChild.getAlpha() != 0.0f) { minDateChild.setAlpha(0.0f); } } } if (checkTopBottom) { if (maxBottom != 0 && maxBottom < (listView.getMeasuredHeight() - listView.getPaddingBottom())) { resetScroll(); } else if (minTop != Integer.MAX_VALUE && minTop > listView.getPaddingTop() + actionBar.getTranslationY()) { scrollWithoutActionBar(listView, -listView.computeVerticalScrollOffset()); resetScroll(); } } }
Example 20
Source File: ItemTouchHelper.java From Carbon with Apache License 2.0 | 3 votes |
/** * 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); } } }