/** * Scroll the deck list so that it is centered on the current deck. * * @param did The deck ID of the deck to select. */ private void scrollDecklistToDeck(long did) { int position = mDeckListAdapter.findDeckPosition(did); mRecyclerViewLayoutManager.scrollToPositionWithOffset(position, (mRecyclerView.getHeight() / 2)); }
public void postSetSelection(final int position) { clearFocus(); post(() -> { ((LinearLayoutManager) getLayoutManager()).scrollToPositionWithOffset(position, 0); // Set initial accessibility focus to selected day restoreAccessibilityFocus(mSelectedDay); if (pageListener != null) pageListener.onPageChanged(position); }); }
int offset = topMargin - parentTopPadding - itemTopMargin; ((LinearLayoutManager) mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(flatPosition, offset); } else if (bottomRoom >= (totalChildrenHeight + bottomMargin)) {
manager.scrollToPositionWithOffset(selectedItem - itemsAbove, 0);
@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); } }
private void setCompactMode(boolean compactMode, boolean force) { if (mCompactMode == compactMode && !force) return; mCompactMode = compactMode; if (compactMode) { mMaxHeight = mContext.getResources().getDimensionPixelSize(R.dimen.dialog_bottom_user_header_height_compact); mMinHeight = mContext.getResources().getDimensionPixelSize(R.dimen.dialog_bottom_user_header_min_height_compact); mBottomMargin = mContext.getResources().getDimensionPixelSize(R.dimen.dialog_bottom_user_header_bottom_margin_compact); mNameBottomMargin = mContext.getResources().getDimensionPixelSize(R.dimen.dialog_bottom_user_header_name_bottom_margin_compact); mTargetNameBottomMargin = mContext.getResources().getDimensionPixelSize(R.dimen.dialog_bottom_user_header_name_bottom_margin_target_compact); } else { mMaxHeight = mContext.getResources().getDimensionPixelSize(R.dimen.dialog_bottom_user_header_height); mMinHeight = mContext.getResources().getDimensionPixelSize(R.dimen.dialog_bottom_user_header_min_height); mBottomMargin = mContext.getResources().getDimensionPixelSize(R.dimen.dialog_bottom_user_header_bottom_margin); mNameBottomMargin = mContext.getResources().getDimensionPixelSize(R.dimen.dialog_bottom_user_header_name_bottom_margin); mTargetNameBottomMargin = mContext.getResources().getDimensionPixelSize(R.dimen.dialog_bottom_user_header_name_bottom_margin_target); } RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mContainer.getLayoutParams(); params.height = mMaxHeight; mContainer.setLayoutParams(params); mRecyclerView.setPadding(0, mMaxHeight, 0, 0); ((LinearLayoutManager) mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(0, 0); setScrollY(0); }
private void scrollToPositionWithOffset(int position, int offset, boolean adjustForStickyHeader) { // Reset pending scroll. setPendingScroll(RecyclerView.NO_POSITION, INVALID_OFFSET); // Adjusting is disabled. if (!adjustForStickyHeader) { super.scrollToPositionWithOffset(position, offset); return; } // There is no header above or the position is a header. int headerIndex = findHeaderIndexOrBefore(position); if (headerIndex == -1 || findHeaderIndex(position) != -1) { super.scrollToPositionWithOffset(position, offset); return; } // The position is right below a header, scroll to the header. if (findHeaderIndex(position - 1) != -1) { super.scrollToPositionWithOffset(position - 1, offset); return; } // Current sticky header is the same as at the position. Adjust the scroll offset and reset pending scroll. if (mStickyHeader != null && headerIndex == findHeaderIndex(mStickyHeaderPosition)) { int adjustedOffset = (offset != INVALID_OFFSET ? offset : 0) + mStickyHeader.getHeight(); super.scrollToPositionWithOffset(position, adjustedOffset); return; } // Remember this position and offset and scroll to it to trigger creating the sticky header. setPendingScroll(position, offset); super.scrollToPositionWithOffset(position, offset); }
/** * 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"); } }
private void updateScrollPosition() { int pos = mAdapter.getSelectedItemIndex(); if (pos == -1) return; int s = mLayoutManager.findFirstCompletelyVisibleItemPosition(); int e = mLayoutManager.findLastCompletelyVisibleItemPosition(); if (pos < s || pos > e) { mLayoutManager.scrollToPositionWithOffset(pos, (mLayoutManager.getHeight() - mLayoutManager.getPaddingTop() - mLayoutManager.getPaddingBottom()) / 3); } }
pos *= mItemCount - getBottomViewCount() - 1; pos = Math.min(Math.max(pos, 0.f), mItemCount - getBottomViewCount() - 1); ((LinearLayoutManager) mRecyclerView.getLayoutManager()).scrollToPositionWithOffset((int) pos, 0); mScrollPos = pos; invalidate();
layoutManager.scrollToPositionWithOffset(spanCount * exactItemPos / scrollPosState.rowHeight, -(exactItemPos % scrollPosState.rowHeight)); } catch (ArithmeticException e) { /* Avoids issues where children of RV have not yet been laid out */ } layoutManager.scrollToPositionWithOffset(exactItemPos, offset); return 0;
layoutManager.scrollToPositionWithOffset(pos, posView.getTop() - topMargin); } else { int leftMargin = ((MarginLayoutParams) posView.getLayoutParams()).leftMargin; layoutManager.scrollToPositionWithOffset(pos, posView.getLeft() - leftMargin);
LinearLayoutManager llm = (LinearLayoutManager) lm; int offset = getBottomOffset(llm.getOrientation(), 0); llm.scrollToPositionWithOffset(position, offset); } else if (lm instanceof StaggeredGridLayoutManager) { final StaggeredGridLayoutManager sglm = (StaggeredGridLayoutManager) lm;
LinearLayoutManager llm = (LinearLayoutManager) lm; int offset = getCenterOffset(llm.getOrientation(), 0); llm.scrollToPositionWithOffset(position, offset); } else if (lm instanceof StaggeredGridLayoutManager) { final StaggeredGridLayoutManager sglm = (StaggeredGridLayoutManager) lm;
if (ids.get(i).equals(nearMessage)) { ((LinearLayoutManager) mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(i, 0);
int index = mAdapter.findMessageWithId(msgId); if (index != -1) ((LinearLayoutManager) mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(index, 0); else reloadMessages(SettingsHelper.getInstance(getContext()), msgId);