Android RecycleView上下滑动带动ViewPage2左右滑动

一,问题描述:
当页面是由导航栏,,列表 组成的时候,上下滑动,总是不经意的带动了的左右滑动 , 太灵敏 。
【Android RecycleView上下滑动带动ViewPage2左右滑动】解决问题方法核心:分发事件 。(其实看了一遍并没什么思路)
思路:从布局开始:++
而我们是在中,又在中 。也就是说是的父布局 。
然而,看了一下并不能被继承 。那我们可以做的就是,在 滑动的时候,去影响  , 怎么去影响他呢?这是个问题 。
先看下 子控件 的拦截方法都有啥
自定义View 继承实现这个方法
这是的事件分发方法,我们的操作就要在这个里面 。
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {when (ev!!.action) {//按下MotionEvent.ACTION_DOWN -> {//此时,得到手指坐标 X,Y}//移动MotionEvent.ACTION_MOVE -> {//移动的距离}//这里 抬起手指,和取消动作 。MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL ->{}}return super.dispatchTouchEvent(ev)}

Android RecycleView上下滑动带动ViewPage2左右滑动

文章插图
怎么操作父布局
下面这个接口→视图父类 。
Defines the responsibilities for a class that will be a parent of a View.This is the API that a view sees when it wants to interact with its parent.
解释:大概意思是,使用这个类,可以得到当前布局(使用这个方法的布局)的父布局 。并与之交互 。
public interface ViewParent { //其他方法略.../*** 这个方法:如果父元素存在,返回父元素;或者null 。*/public ViewParent getParent();/*** 还有这个:当子View不希望被父View调用时使用,意思就是我自己来,不让父布局管 。*true:拦截 , false:不拦截*/public void requestDisallowInterceptTouchEvent(boolean disallowIntercept);...}