skip to Main Content

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


  1. 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
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search