How to return to the top of an Activity?

Asked

Viewed 168 times

1

Following the standards of Material design, by clicking on a button of a Bottom Navigation that is already active, Activity should roll to the top I have a Framelayout with Coordinatorlayout, which in turn has a Recyclerview (a list of elements). My intention is to make Activity roll to the top.

1 answer

1


You can, by clicking the button with onClick, use the method scrollToPositionWithOffset class LinearLayoutManager, passing as parameter the position 0,0. Behold:

lManager.scrollToPositionWithOffset(0, 0);

Then I’d stay that way:

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

Reference to that answer in Soen.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.