ViewPager滑动和RecyclerView滚动之间的冲突

时间:2018-03-28 08:38:26

标签: android android-recyclerview

在我的应用中,我有一个ViewPager,它有不同的标签。每个选项卡仅由RecyclerView组成,可以垂直滚动。

我的问题是,当我尝试导航到其他标签并向左或向右滑动时,会先检测RecyclerView's滚动,而不是转到另一个标签,RecyclerView会滚动。

我尝试了以下回收商视图的属性:

         rv_home.setNestedScrollingEnabled(false);

该时间ViewPager滑动按预期工作但recycler view的垂直滚动已停用。我该怎么办?

3 个答案:

答案 0 :(得分:5)

v_home.setHasFixedSize(true);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext(),
            LinearLayoutManager.VERTICAL, false);
    layoutManager.setAutoMeasureEnabled(true);
    rv_home.setNestedScrollingEnabled(false);
    rv_home.setLayoutManager(layoutManager);

试试这个

答案 1 :(得分:0)

这是因为您可能已经将RecyclerView项作为宽度的匹配父项。拿走包装的内容,它可能对您也对我有用。

答案 2 :(得分:0)

 rootView.nested_scroll.setOnScrollChangeListener(object : NestedScrollView.OnScrollChangeListener {
        override fun onScrollChange(
            v: NestedScrollView?,
            scrollX: Int,
            scrollY: Int,
            oldScrollX: Int,
            oldScrollY: Int
        ) {

            if (v?.getChildAt(v.getChildCount() - 1) != null) {
                if ((scrollY >= (v.getChildAt(v.getChildCount() - 1).getMeasuredHeight() - v.getMeasuredHeight())) &&
                    scrollY > oldScrollY
                ) {
                    var visibleItemCount = (recyclerView.layoutManager as LinearLayoutManager).getChildCount()
                    var totalItemCount = (recyclerView.layoutManager as LinearLayoutManager).getItemCount()
                    var pastVisiblesItems =
                        (recyclerView.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()

                    if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
                //Load Your Items Here

                    }
                }
            }
        }
    })