繁体   English   中英

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

[英]Conflict between ViewPager swipe and RecyclerView scroll

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

我的问题是,当我尝试导航到其他选项卡并向左或向右滑动时,将首先检测到RecyclerView's滚动,而不是转到另一个选项卡,从而使RecyclerView滚动。

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

         rv_home.setNestedScrollingEnabled(false);

当时ViewPager滑动正常,但是禁用了recycler view垂直滚动。 我该怎么办?

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

尝试这个

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

 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

                    }
                }
            }
        }
    })

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM