Home > Back-end >  How can I control position of scroll in recyclerview
How can I control position of scroll in recyclerview

Time:09-12

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

CodePudding user response:

You can try enter image description here

CodePudding user response:

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