RecyclerView 在一个设置BottomSheetBehavior的LinearLayout中,BottomSheet弹起时RecyclerView 无法滑动,通过重写Touch监听由RV的不同状态进行事件消费处理滑动冲突
recyclerView.apply {
val linearLayoutManager = LinearLayoutManager(requireContext())
layoutManager = linearLayoutManager
adapter = rvAdapter
var touched = false
setOnTouchListener(View.OnTouchListener { v, event ->
if(linearLayoutManager.findFirstCompletelyVisibleItemPosition()==0 && touched){
//RV到顶部item完全显示时将滑动交给父控件
v.parent.requestDisallowInterceptTouchEvent(false)
touched = false
return@OnTouchListener true
}
when (event.action) {
MotionEvent.ACTION_DOWN -> {
//不允许父控件拦截触摸事件
v.parent.requestDisallowInterceptTouchEvent(true)
}
MotionEvent.ACTION_UP -> {
//允许父控件拦截触摸事件
v.parent.requestDisallowInterceptTouchEvent(false)
touched = true
}
}
v.performClick()
v.onTouchEvent(event)
true
})
}