If you want to scroll your recyclerview automatically, you can use the below code. Just add this code after setting your recyclerview adapter
Timer timerx;
//first add this global field in your class
//This is the code for auto scroll
try {
Timer timer = new Timer();
timerx = timer;
final int time = 4000; // it's the delay time for sliding between items in recyclerview
timer.schedule(new TimerTask() {
@Override
public void run() {
try {
if (linearLayoutManager.findLastCompletelyVisibleItemPosition() < (topPlayersAdapter.getItemCount() - 1)) {
linearLayoutManager.smoothScrollToPosition(ToprecyclerView, new RecyclerView.State(), linearLayoutManager.findLastCompletelyVisibleItemPosition() + 1);
} else if (linearLayoutManager.findLastCompletelyVisibleItemPosition() == (topPlayersAdapter.getItemCount() - 1)) {
linearLayoutManager.smoothScrollToPosition(ToprecyclerView, new RecyclerView.State(), 0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}, 0, time);
} catch (Exception e) {
e.printStackTrace();
}
Java is the programming language which was developed in the early days of the computer age. It has been a service for android developers to develop apps easily without investing much time and money on learning a new language. With that said, Java can be used on almost every platform, including Windows, Mac and any Linux based operating system as well. In this article we’re going to learn how to auto scroll RecyclerView in Android Java.