RecyclerView的item中嵌套RecyclerView的滑动冲突解决
mBinding.rvBrand.addOnItemTouchListener(object : RecyclerView.OnItemTouchListener {
override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {
}
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
// 外层RV滑动与内层布局滑动冲突解决
// 找到被点击位置的item的rootView
val itemView = rv.findChildViewUnder(e.x, e.y)
if (itemView != null) {
// 通过rootView找到对应的ViewHolder
val holder = rv.getChildViewHolder(itemView)
val recyclerViewSmallCoupon = holder.itemView.recyclerViewSmallCoupon
recyclerViewSmallCoupon?.let {
recyclerViewSmallCoupon.requestDisallowInterceptTouchEvent(true)
}
}
return false
}
override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {
}
})