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"
网友评论