Scroll to top in RecyclerView with LinearLayoutManager

Continuing from above comments, ideally, replacing


in the onClick of the floating action button with

mLayoutManager.scrollToPositionWithOffset(0, 0);

should work. You can also remove the SnackBar code, because you don’t need it anyways. So, all in all your above method should look like

public void setFloatingActionButton(final View view) {
    float actionButton = ( getActivity()
    actionButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView
            layoutManager.scrollToPositionWithOffset(0, 0);

And if you say that the above doesnt work, then test if the onClick() is even being called or not. Try adding a log message in it and see if its printed.

Leave a Comment