美文网首页UI
Scrollview和RecyclerView滑动冲突问题解决

Scrollview和RecyclerView滑动冲突问题解决

作者: 走在冷风中吧 | 来源:发表于2018-06-30 20:35 被阅读304次

1.Scrollview和横向RecyclerView滑动冲突问题解决
重写scrollview的onInterceptTouchEvent方法, 即可解决recyclerview横向滑动不畅的问题.

   override fun onInterceptTouchEvent(e: MotionEvent): Boolean {

        var intercept = super.onInterceptTouchEvent(e)

        when (e.action) {

            MotionEvent.ACTION_DOWN -> {
                lastX = e.x
                lastY = e.y
            }
            MotionEvent.ACTION_MOVE -> {
                // 只要横向大于竖向,就拦截掉事件。
                // 部分机型点击事件(slopx==slopy==0),会触发MOVE事件。
                // 所以要加判断(slopX > 0 || sloy > 0)
                val slopX = Math.abs(e.x - lastX)
                val slopY = Math.abs(e.y - lastY)
                //  Log.log("slopX=" + slopX + ", slopY="  + slopY);
                if ((slopX > 0 || slopY > 0) && slopX <= slopY) {
                    requestDisallowInterceptTouchEvent(true)
                    intercept = true
                }else{
                    intercept = false
                }

            }
            MotionEvent.ACTION_UP -> intercept = false
        }
        return intercept
    }

2 : NestedSrollview和Recycleview冲突解决:
NestedSrcollview:

android:fillViewport="true"

RecycleView:

android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"

相关文章

网友评论

    本文标题:Scrollview和RecyclerView滑动冲突问题解决

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