【问题标题】:Get Scroll in Recyclerview inside Nested Scrollview在嵌套滚动视图中的 Recyclerview 中获取滚动
【发布时间】:2018-09-05 04:43:57
【问题描述】:

我有这个代码 addOnScrollListener of recyclerview,它位于嵌套滚动视图中

 mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                mScrollState = newState;
                if (newState == RecyclerView.SCROLL_STATE_IDLE && adapter.getItemCount() > 0) {
                    mCalculator.onScrollStateIdle();
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                mCalculator.onScrolled(mScrollState);
            }
        });

当我滚动视图时,我需要进入 addOnScrollListener 中的这些方法。 但不幸的是,滚动时没有进入这个方法。谁能帮我 如何在嵌套的scrollview中获取recyclerview的滚动

【问题讨论】:

标签: android android-recyclerview android-nestedscrollview


【解决方案1】:

代表 new RecyclerView.OnScrollListener() 尝试使用 NestedScrollView.OnScrollChangeListener。它可能会帮助您解决您的问题

nestedScrollView.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, x, y, x1, y1) -> {
            if(v.getChildAt(v.getChildCount() - 1) != null) {
                if ((x >= (v.getChildAt(v.getChildCount() - 1).getMeasuredHeight() - v.getMeasuredHeight())) &&
                        y > y1) {
                        //code to fetch more data for endless scrolling
                }
            }
        });

【讨论】:

  • 抱歉没有帮助。问题是我的列表由文本、图像和视频三个布局组成。当用户滚动并到达视频对用户完全可见的视频时,视频应该自动播放。为此,我需要 recyclerview 滚动
【解决方案2】:

我刚刚使用手势动作处理了问题

【讨论】:

    猜你喜欢
    • 2016-01-12
    • 2016-09-15
    • 1970-01-01
    • 2019-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多