@Override public void run() { if (mRecyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) { ((StaggeredGridLayoutManager) mRecyclerViewLayoutManager) .scrollToPositionWithOffset(0, 0); } } });
@Override public void run() { int first = getFirstVisiblePosition(); int last = getLastVisiblePosition(); int childPosition = 0; for (int i = first; i < last; i++) { if (i == position) { int offset = getCenterOffset(sglm.getOrientation(), childPosition); sglm.scrollToPositionWithOffset(position, offset); break; } childPosition++; } } });
@Override public void run() { int first = getFirstVisiblePosition(); int last = getLastVisiblePosition(); int childPosition = 0; for (int i = first; i < last; i++) { if (i == position) { int offset = getBottomOffset(sglm.getOrientation(), childPosition); sglm.scrollToPositionWithOffset(position, offset); break; } childPosition++; } } });
/** * Scrolls a view at the given position to top (vertical layout) or left (horizontal layout). * * @param position The adapter position. */ public void head(int position) { if (mIgnoreIfCompletelyVisible && isCompletelyVisible(position)) { return; } if (mIgnoreIfVisible && isVisible(position)) { return; } LayoutManager lm = getLayoutManager(); if (lm instanceof LinearLayoutManager) { LinearLayoutManager llm = (LinearLayoutManager) lm; llm.scrollToPositionWithOffset(position, 0); } else if (lm instanceof StaggeredGridLayoutManager) { final StaggeredGridLayoutManager sglm = (StaggeredGridLayoutManager) lm; sglm.scrollToPositionWithOffset(position, 0); } else { throw new UnsupportedOperationException("unsupported layout manager"); } }
final StaggeredGridLayoutManager sglm = (StaggeredGridLayoutManager) lm; int offset = getBottomOffset(sglm.getOrientation(), 0); sglm.scrollToPositionWithOffset(position, offset);
final StaggeredGridLayoutManager sglm = (StaggeredGridLayoutManager) lm; int offset = getCenterOffset(sglm.getOrientation(), 0); sglm.scrollToPositionWithOffset(position, offset);