How can I control position of scroll in recyclerview

Viewed 22

i need when scroll to top position or first item show in the recyclerview do something like show toolbar and when scroll down or hide first item in recyclerview hide toolbar or do somethinghing

2 Answers

Try this:

  contenuRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);

            if (yourLayoutManager.findFirstVisibleItemPosition() != 1){
                // visible toolbar
            } else {
                // gone toolbar
            }

        }
    });

yourLayoutManager can be :

  • LinearLayoutManger
  • GridLayoutManager
  • StaggeredGridLayoutManager
Related