NestedScrollView 中 RecyclerView 的 ScrollListener? [英] ScrollListener for RecyclerView inside NestedScrollView?

查看:63
本文介绍了NestedScrollView 中 RecyclerView 的 ScrollListener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 NestedScrollView 中使用了 RecyclerView.为了平滑滚动

I am using RecyclerView inside NestedScrollView. For smooth scrolling

nestedScrollView.setNestedScrollingEnabled(true);
recyclerView.setNestedScrollingEnabled(false);

而且这个 RecyclerView 是动态的,在 scroll 上动态添加行.但是滚动侦听器不起作用 NestedScrollingEnabled 是假的.

And this RecyclerView is dynamic, dynamically adding rows on the scroll. But scroll listener is not working NestedScrollingEnabled is false.

推荐答案

        scroller.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

                if (scrollY > oldScrollY) {
                    Log.i(TAG, "Scroll DOWN");
                }
                if (scrollY < oldScrollY) {
                    Log.i(TAG, "Scroll UP");
                }

                if (scrollY == 0) {
                    Log.i(TAG, "TOP SCROLL");
                }

                if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
                    Log.i(TAG, "BOTTOM SCROLL");
    f (viewGroup1.getChildAt(viewGroup1.getChildCount() - 1) instanceof RecyclerView){
//add code here }

                }
           }
        });

这篇关于NestedScrollView 中 RecyclerView 的 ScrollListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆