簡體   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