This will also work but but really slow and not effectively. Recycelerview do not load at same speed everytime that is why this one will be a bit laggy.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
myRecyclerview.scrollToPosition(position);
}
}, 200);
But after a long strugle i figure out a improved version of this which works really really well.
private void scrolltopos() {
int index = 0;
if (layoutManager.findFirstCompletelyVisibleItemPosition() != index) {
recyclerview.getLayoutManager().scrollToPosition(index);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
scrolltopos();
}
}, 1000);
} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
recyclerview.setVisibility(View.VISIBLE);
}
}, 1000);
}
}
This code is like a loop. Its gonna keep running untill it reaches your desired position. On top of that it will automatically make recyclerview visible after operation.