There is a RecyclerView with dynamic data loading: when the penultimate item in the list is reached, the following items start loading.
Let the user scroll the list to the state when the penultimate element of the list became visible on the screen. Data loading has begun, and an element with a progress bar is added to the end of the list.
Suppose that in the process of loading data, the user has scrolled the list to the end: on the screen we can fully see the element with the progress bar.
If an error occurred during data loading, the element with the progress bar is replaced with the element with an error message.
The element with the error message is more high than the element with the progress bar. Then, when replacing an element with a progress bar with an element with an error message, the element with an error message is not fully visible.
After replacing an element with a progress bar with an element with an error message, you need to programmatically scroll the list to the end in order for the element with an error to be completely visible.
What I tried:
Time:
mRecyclerView.scrollToPosition(mAdapter.getItemCount()-1); Two:
LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager(); layoutManager.scrollToPosition(mAdapter.getItemCount()-1); where mAdapter is an adapter for mRecyclerView .
In these embodiments, there is no change in the scrolling state.