How to get back to the top of an Activity?

1

Following material design standards, clicking a button in a Bottom Navigation that is already active should scroll to the top I have a FrameLayout with CoordinatorLayout, which in turn has a RecyclerView (a list of elements). My intention is to make the activity roll to the top.

    
asked by anonymous 11.04.2017 / 15:30

1 answer

1

You can, by clicking on the onClick button, use the scrollToPositionWithOffset method of the LinearLayoutManager class, passing the 0,0 parameter to the parameter. See:

lManager.scrollToPositionWithOffset(0, 0);

Then it would look like this:

bottonButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        LinearLayoutManager lManager = (LinearLayoutManager) mRecyclerView
                .getLayoutManager();
        lManager.scrollToPositionWithOffset(0, 0);
    }
});

Reference to this answer in SOen .

    
11.04.2017 / 16:46