How to auto scroll RecyclerView
smoothly so that user can see all the elements of the RecyclerView and scroll again from the start - as in News Feed etc.
You can also implement it in this way, after setting recyclerview to adapter
final int duration = 10;
final int pixelsToMove = 263;
final Handler mHandler = new Handler(Looper.getMainLooper());
final Runnable SCROLLING_RUNNABLE = new Runnable() {
@Override
public void run() {
recyclerView.smoothScrollBy(pixelsToMove, 0);
mHandler.postDelayed(this, duration);
}
};
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int lastItem = horizontalLayoutManager.findLastCompletelyVisibleItemPosition();
if (lastItem == horizontalLayoutManager.getItemCount() - 1) {
mHandler.removeCallbacks(SCROLLING_RUNNABLE);
Handler postHandler = new Handler();
postHandler.postDelayed(new Runnable() {
@Override
public void run() {
quickTips.setAdapter(null);
quickTips.setAdapter(adapter);
mHandler.postDelayed(SCROLLING_RUNNABLE, 2000);
}
}, 2000);
}
}
});
mHandler.postDelayed(SCROLLING_RUNNABLE, 2000);