Skip to content

ViewPager2嵌套SmartRefreshLayout时,在下拉刷新或者上拉加载过程中,如果横向滑动距离过大时事件就交给ViewPager2了会导致横向滑动。 #1260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
YuToo opened this issue Oct 27, 2020 · 7 comments

Comments

@YuToo
Copy link

YuToo commented Oct 27, 2020

比如下拉刷新拉到一半了,这个时候如果再进行横向滑动,距离过大页面就横向滑动了,体验有点不太对,容易造成误切页面。上拉一样,很容易造成切换页面。特别是对于快速下拉刷新操作时。

@SmartKidsLOL
Copy link

遇到同样问题,mark,同样case下下拉刷新或者上拉加载后,RecyclerView会强制收到ActionUp事件,但手指还没有松开,事件却交给了ViewPager2,所以导致了误切页面

@liudaohong
Copy link

是的 都遇到这个问题了

@liudaohong
Copy link

这个问题有解决方案了吗 没有的话就需要自己去集成SmartRefreshLayout 去修改吗

@liudaohong
Copy link

不是你这个 你这个解决不了 我一直都是你这个 自定义RecyclerView 而且x必须大于10倍y 才给
这个问题是上拉后 刷新了 事件就被给ViewPager2 了 所以就导致了 这个问题 RecycyelrView 根本获取不到 TouchEvent

@SmartKidsLOL
Copy link

详情具体看SmartRefreshLayout的源码中的finishLoadMore或者对应的下拉刷新方法,它的mNestedInProgress为True时,会分发一个ActionUp事件,有需要的话把这句注释掉,再改一改也能将就用

@w1984908499
Copy link

请问这个问题解决了吗

@liudaohong
Copy link

我目前用的这个 修改Viewpager2 的滑动系数 里面具体多少 你自己可以调整 不过这个值 我自己用着还行

/**
* 改变ViewPager2的滑动系数
* */
public static void changeViewPaer2 (ViewPager2 vp){
try {
final Field recyclerViewField = ViewPager2.class.getDeclaredField("mRecyclerView");
recyclerViewField.setAccessible(true);

        final RecyclerView recyclerView = (RecyclerView) recyclerViewField.get(vp);//vb.viewpagerHome为要改变滑动距离的viewpager2控件

        final Field touchSlopField = RecyclerView.class.getDeclaredField("mTouchSlop");
        touchSlopField.setAccessible(true);

         final int touchSlop = (int) touchSlopField.get(recyclerView);
         touchSlopField.set(recyclerView, touchSlop*4);//通过获取原有的最小滑动距离 *n来增加此值
        //touchSlopField.set(recyclerView, 200);//自己写一个值
    } catch (Exception ignore) {
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants