recyclerView.getLayoutManager().scrollToPosition(messages.size());
private void setRecyclerViewPosition(float y) { if (recyclerView != null && recyclerView.getAdapter() != null) { int itemCount = recyclerView.getAdapter().getItemCount(); float proportion; if (mHandleView.getY() == 0) { proportion = 0f; } else if (mHandleView.getY() + mHandleView.getHeight() >= mViewHeight - sTrackSnapRange) { proportion = 1f; } else { proportion = y / mViewHeight; } int scrolledItemCount = Math.round(proportion * itemCount); int targetPos = Utility.getValueInRange(0, itemCount - 1, scrolledItemCount); recyclerView.getLayoutManager().scrollToPosition(targetPos); if (mainImageAdapter != null) { String text = mainImageAdapter.getSectionMonthYearText(targetPos); mBubbleView.setText(text); if (text.equalsIgnoreCase("")) { mBubbleView.setVisibility(View.GONE); } } } }
private void setRecyclerViewPosition(float y) { if (recyclerView != null && recyclerView.getAdapter() != null) { int itemCount = recyclerView.getAdapter().getItemCount(); float proportion; if (handleView.getY() == 0) { proportion = 0f; } else if (handleView.getY() + handleHeight >= viewHeight - TRACK_SNAP_RANGE) { proportion = 1f; } else { proportion = y / (float) viewHeight; } int scrolledItemCount = Math.round(proportion * itemCount); if (isLayoutReversed(recyclerView.getLayoutManager())) { scrolledItemCount = itemCount - scrolledItemCount; } int targetPos = getValueInRange(0, itemCount - 1, scrolledItemCount); recyclerView.getLayoutManager().scrollToPosition(targetPos); if (showBubble && sectionIndexer != null) { bubbleView.setText(sectionIndexer.getSectionText(targetPos)); } } }
@Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { recyclerView.removeOnLayoutChangeListener(this); final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); View viewAtPosition = layoutManager.findViewByPosition(MainActivity.currentPosition); // Scroll to position if the view for the current position is null (not currently part of // layout manager children), or it's not completely visible. if (viewAtPosition == null || layoutManager .isViewPartiallyVisible(viewAtPosition, false, true)) { recyclerView.post(() -> layoutManager.scrollToPosition(MainActivity.currentPosition)); } } });
/** * Called when the observed {@link androidx.lifecycle.LiveData} is changed. * <p> * This method will update the related adapter and the {@link androidx.swiperefreshlayout.widget.SwipeRefreshLayout} if present. * * @param model The data observed by the {@link androidx.lifecycle.LiveData}. */ @Override protected void onDataReady(List<AlbumModel> model) { super.onDataReady(model); // Reset old scroll position if (mLastPosition >= 0) { mRecyclerView.getLayoutManager().scrollToPosition(mLastPosition); mLastPosition = -1; } }
public void scrollListTo(final int position, final boolean animated) { listPos = position; if (animated) { recyclerView.smoothScrollToPosition(listPos); } else { recyclerView.getLayoutManager().scrollToPosition(listPos); } }