Android Layout: Horizontal Recyclerview inside a Vertical Recyclerview inside a Viewpager with Scroll Behaviors

前端 未结 6 576
一整个雨季
一整个雨季 2020-11-30 20:33

This is the app I\'m trying to build with all the elements mapped out below:

Everything works, however, I want the inner horizontal recyclerview not to capt

6条回答
  •  感情败类
    2020-11-30 21:18

    if any one still looking , try this :

    private val Y_BUFFER = 10
    private var preX = 0f
    private var preY = 0f
    
    mView.rv.addOnItemTouchListener(object : RecyclerView.OnItemTouchListener {
            override fun onTouchEvent(p0: RecyclerView, p1: MotionEvent) {
    
                }
    
            override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
                    when (e.action) {
                        MotionEvent.ACTION_DOWN -> rv.parent.requestDisallowInterceptTouchEvent(true)
                        MotionEvent.ACTION_MOVE -> {
                            if (Math.abs(e.x - preX) > Math.abs(e.y - preY)) {
                                rv.parent.requestDisallowInterceptTouchEvent(true)
                            } else if (Math.abs(e.y - preY) > Y_BUFFER) {
                                rv.parent.requestDisallowInterceptTouchEvent(false)
                            }
    
                        }
                    }
                    preX = e.x
                    preY = e.y
                    return false
                }
    
                override fun onRequestDisallowInterceptTouchEvent(p0: Boolean) {
                }
            })
    

    it checks if currently scrolling horizontal then don't allow parent to handel event

提交回复
热议问题