简体   繁体   English

如何在 recyclerview 中控制滚动的 position

[英]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我需要当滚动到顶部 position 或 recyclerview 中显示的第一个项目时执行显示工具栏之类的操作,当向下滚动或隐藏 recyclerview 中的第一个项目时隐藏工具栏或做某事

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: yourLayoutManager 可以是:

  • LinearLayoutManger线性布局管理器
  • GridLayoutManager网格布局管理器
  • StaggeredGridLayoutManager交错网格布局管理器

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在RecylerView布局中修复按钮的位置? 我不希望按钮与RecyclerView中的图像一起滚动 - How can I fix the position of buttons in a RecylerView layout? I don't want the buttons to scroll along with the image in RecyclerView 如何在片段中维护滚动 position? - How can I maintain scroll position in a fragment? 滚动到recyclerview的最后一个位置 - scroll to last position of recyclerview 在RecyclerView中保留滚动位置 - Retain scroll position in RecyclerView 如何在 android 中制作滚动视图以剪辑到滚动 position? - How can I make a scroll view that clips to a scroll position in android? 如何更新RecyclerView中项目的位置? - How can I update the position of an item inside of a RecyclerView? 如何使用许多类型的customViewHolder在recyclerView中实现recyclerView.smoothScrollToPosition(position)? - How can I implement recyclerView.smoothScrollToPosition(position) in recyclerView with many types of customViewHolder? 在 Recyclerview 中,如何将初始滚动位置更改为第一项的顶部? - In Recyclerview, how to change initial scroll position to the top of first item? LinearLayout 和 NestedScrollView 中的 RecyclerView - 如何滚动到某个位置的项目顶部? - RecyclerView inside LinearLayout and NestedScrollView - How to scroll to top of item on a certain position? 如何在RecyclerView中执行从顶部到某个位置的滚动项目? - How in RecyclerView perform scroll item with some position to top?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM