youlookwhat / ByRecyclerView

🔥 RecyclerView 下拉刷新、上拉松手/自动加载更多、item点击/长按、item局部刷新、头布局/尾布局/状态布局、万能分割线、Skeleton骨架图、极简adapter、嵌套滑动置顶
https://youlookwhat.github.io/ByRecyclerView
Apache License 2.0
798 stars 139 forks source link

关于回到顶部 #47

Closed Lancerer closed 2 years ago

Lancerer commented 2 years ago

在demo中的coordinatorLayout嵌套滑动置顶例子中,想问下要在加一个一键回到顶部并且下拉刷新怎么做到,对viewPager2内部的recyclerView使用scrollToPosition(0)时,只能到TabLyout部分,头部的appBarLayout里面的无法到顶部

youlookwhat commented 2 years ago

头部的appBarLayout可以使用appBarLayout.setExpanded(true);

这个是展开的操作,看是否符合你的需求

youlookwhat commented 2 years ago

可以监听recyclerView,处于停止的时候再执行appBarLayout.setExpanded(true);

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

            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    appBarLayout.setExpanded(true);
                }
            }
        });

也是需要执行scrollToPosition(0),或者是recyclerView.smoothScrollToPosition(0);

Lancerer commented 2 years ago

这个问题解决了我先把PersistentRecyclerView scrollToposition(0) 然后设置appBarLayout的topAndBottomOffset为0这样可以到达顶部然后进行刷新

youlookwhat commented 2 years ago

好的 可以了就行哈

Lancerer commented 2 years ago

但是现在有一个新的问题,内部的PersistentRecyclerView 他的item又有一个recyclerView,这个recyclerView不但会和PersistentRecyclerView 滑动冲突,我重写了item中的recyclerView的dispatchTouchEvent,内部拦截,但是他好像和appBarLayout又有冲突

youlookwhat commented 2 years ago

一般是建议是item不要有recyclerView,有的话应该也是要设置一个横向的recyclerView,如果是纵向的本身就会有问题。 如果是横向的我还有解决方式,我们之前的项目中有处理横向的情况。

Lancerer commented 2 years ago

项目要求这样实现没办法,大佬有解决办法吗。。。现在的现象是AppBarLayout收缩吸顶的情况下PersistentRecyclerView 还没有滑动到顶部,这个是滑动item的recyclerView时,会直接把appBarLayout拉下来,

youlookwhat commented 2 years ago

你可以将纵向的recyclerView可以设置为横向的呀,将纵向的条数作为span处理,能理解吗

Lancerer commented 2 years ago

没有太明白你说的转换成横向span处理是什么意思,我这个item的recyclerView纵向用于显示台词就一个textview

youlookwhat commented 2 years ago

你设置成横向的recyclerView,横向的行数有[list.size],列数只有一列,可行吗

Lancerer commented 2 years ago

不行啊,他必须要纵向滚动,感谢大佬的指导,我再试试能不能解决内部item的recyclerView和最外部的appBarLayout的冲突

youlookwhat commented 2 years ago

好的哈

Lancerer commented 2 years ago

大佬我在内部recyclerView嵌套的item中的recyclerView设置了isNestedScrollingEnabled=false这个冲突就解决了,但是不知道原因是什么

youlookwhat commented 2 years ago

感觉是rv通过isNestedScrollingEnabled=false这个属性做了处理,解决了就好哈

youlookwhat commented 2 years ago

感觉是rv通过isNestedScrollingEnabled=false这个属性做了处理,解决了就好哈