简体   繁体   中英

How can I control position of scroll in recyclerview

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM