美文网首页
RecyclerView的item中嵌套RecyclerView

RecyclerView的item中嵌套RecyclerView

作者: 颤抖的闪电 | 来源:发表于2021-03-17 18:38 被阅读0次

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) {
                        }

                    })

相关文章

网友评论

      本文标题:RecyclerView的item中嵌套RecyclerView

      本文链接:https://www.haomeiwen.com/subject/hrbecltx.html