NestedScrollView+Viewpager+Recycleview的滑动冲突

NestedScrollView+Viewpager+Recycleview的滑动冲突最新业务需求变化 一个页面多个 Recycleview Viewpager viewpager 实现左右滑动 且可以手动滑动 页面逻辑简单 就是数据比较大 最初的时候实现有滑动冲突 后边使用 NestedScroll 可以实现滑动 但是 Viewpager 不能实现手动滑动 Recycleview 的 item 事件冲突 这个只在华为 7 0 手机上出现 华为 8 0 及三星手机上未发现问题 网上也是各种找 后边看

最新业务需求变化,一个页面多个Recycleview+Viewpager,viewpager实现左右滑动,且可以手动滑动,页面逻辑简单,就是数据比较大,最初的时候实现有滑动冲突,后边使用NestedScrollView可以实现滑动,但是Viewpager不能实现手动滑动,Recycleview的item事件冲突(这个只在华为7.0手机上出现,华为8.0及三星手机上未发现问题)网上也是各种找,后边看是NestedScrollView里面的onInterceptTouchEvent给拦截了

下面贴一下封装完成的NestedScrollView的类,完美实现

public class JudgeNestedScrollView extends NestedScrollView {
    private boolean isNeedScroll = true;
    private float xDistance, yDistance, xLast, yLast;
    private int scaledTouchSlop;

    public JudgeNestedScrollView(@NonNull Context context) {
        super(context);
    }

    public JudgeNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public JudgeNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        scaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                xDistance = yDistance = 0f;
                xLast = ev.getX();
                yLast = ev.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                final float curX = ev.getX();
                final float curY = ev.getY();

                xDistance += Math.abs(curX - xLast);
                yDistance += Math.abs(curY - yLast);
                xLast = curX;
                yLast = curY;
                Log.e("SiberiaDante", "xDistance :" + xDistance + "---yDistance:" + yDistance);
                return !(xDistance >= yDistance || yDistance < scaledTouchSlop) && isNeedScroll;

        }
        return super.onInterceptTouchEvent(ev);
    }


    /*
    改方法用来处理NestedScrollView是否拦截滑动事件
     */
    public void setNeedScroll(boolean isNeedScroll) {
        this.isNeedScroll = isNeedScroll;
    }
}

参考:http://www.cnblogs.com/shen-hua/p/8052459.html

贴一下布局:

<com.xxxx.app.widget.JudgeNestedScrollView android:id="@+id/scorll" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:focusableInTouchMode="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:visibility="gone"> <com.zhy.autolayout.AutoLinearLayout android:id="@+id/lin_content" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#F1F1F1" android:orientation="vertical"> <!--轮播图--> <FrameLayout android:id="@+id/view_lbt" android:layout_width="wrap_content" android:layout_height="590px" /> <!--详情--> <TextView android:id="@+id/tv_header_word" android:layout_width="match_parent" android:layout_height="60px" android:layout_alignTop="@+id/rv" android:layout_marginRight="55px" android:background="@color/gainsboro" android:paddingLeft="40px" android:paddingTop="10px" android:text="A" android:textColor="@color/black" android:textSize="14sp" android:visibility="visible" /> <android.support.v7.widget.RecyclerView android:id="@+id/rv" android:layout_width="match_parent" android:focusable="false" android:layout_height="wrap_content" ></android.support.v7.widget.RecyclerView> </com.zhy.autolayout.AutoLinearLayout> </com.xxxx.app.widget.JudgeNestedScrollView>

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/233641.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Webserver管理系列:11、注意默认的隐含共享

    Webserver管理系列:11、注意默认的隐含共享

    2021年12月8日
    39
  • 湖北用什么dns(lol服务器排名)

    转载自lmg360最终编辑37baby选择一个优秀快速的DNSServer,是上网的一大法宝。收集了一些湖北地区的主要DNS服务器,以作备忘。湖北电信:Name:wuhan.net.cnServedby:ns.hbwhptt.net.cn202.103.0.68ns1.wuhan.net.cn202.103.24.81ns1.hbwhptt.net.cn202.103.0.11…

    2022年4月17日
    98
  • 关于java的外语文献_java英文参考文献(涵盖3年最新120个)

    关于java的外语文献_java英文参考文献(涵盖3年最新120个)近年来,随着我国科学的技术的飞速发展,计算机语言的内容和形式得到了极大的丰富,特别是java语言的广泛应用,它不仅是计算机语言的重要组成部分,同时也是我国程序编写的重要内容之一,java语言的出现和广泛使用,极大的丰富了人们的生产,生活,为人们的工作和学习提供了很大的便利.下面是搜素整理的java英文参考文献的分享,供大家借鉴参考。java英文参考文献一:[1]AbbasMrAnsar,Eli…

    2022年9月30日
    2
  • python导入鸢尾花数据集_python数据挖掘学习笔记】十九.鸢尾花数据集可视化、线性回归、决策树花样分析…

    #2018-04-0516:57:26AprilThursdaythe14week,the095daySZSSMRpython数据挖掘学习笔记】十九.鸢尾花数据集可视化、线性回归、决策树花样分析1.鸢尾花数据集可视化分析2.线性回归分析鸢尾花花瓣长度和宽度的关系3.决策树分析鸢尾花数据集4.Kmeans聚类分析鸢尾花数据集一.鸢尾花数据集介绍本章采用Python的Sklea…

    2022年4月16日
    126
  • onResume无限循环

    onResume无限循环今天在做权限申请,写完后,发现点界面上任何东西都无法响应,整个界面处于卡死状态。查看Log,onResume和onPause在不停的执行,debug排查发现是因为请求权限导致的。由于考虑到权限必须获得,否则没法去读取数据和开启功能,所以就想着放在onResume里。请求权限相当于打开了一个请求权限界面,app会先执行onPause,如果有多个权限申请,点了允许,生命周期会执

    2022年6月2日
    31
  • oracle中怎么跳出循环,oracle 跳出循环方法

    oracle中怎么跳出循环,oracle 跳出循环方法记录exit和return的用法1.exit用来跳出循环Oracle代码:declareV_KBPvarchar2(10);beginloopIFV_KBPISNULLTHENEXIT;ENDIF;endloop;dbms_output.put_line(‘退出’);end;exit跳出循环(示例中跳到第8行)后,仍然输出“退出”2.return跳记录…

    2022年6月4日
    37

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号