Android ViewPager with RecyclerView works incorrectly inside BottomSheet

后端 未结 7 1066
故里飘歌
故里飘歌 2020-12-13 02:51

When I try to scroll list, sometimes this works incorrect - BottomSheet intercepts the scroll event and hides.

How to reproduce this:

  1. Open Bottom Sheet
7条回答
  •  渐次进展
    2020-12-13 03:32

    Assuming page is a NestedScrollView, I was able to solve the problem by toggling its isNestedScrollingEnabled property depending on whether or not it's the incoming or outgoing page.

    val viewPager = findViewById(R.id.viewPager)
    
    viewPager.setPageTransformer(false) { page, position ->
        if (position == 0.0f) {
            page.isNestedScrollingEnabled = true
        } else if (position % 1 == 0.0f) {
            page.isNestedScrollingEnabled = false
        }
    }
    

提交回复
热议问题