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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • java生成指定位数的随机数「建议收藏」

    java生成指定位数的随机数「建议收藏」java生成指定位数的随机数

    2022年4月23日
    210
  • js字符串截取为数组

    js字符串截取为数组varstr=”hello,word,java,eclipse,jsp”;//字符串截取为数组varstrArr=str.split(“,”);for(j=0,len=strArr.length;j<len;j++){alert(strArr[j]);};

    2022年5月1日
    56
  • PathFileExists用法「建议收藏」

    PathFileExists用法「建议收藏」BOOLPathFileExists(LPCTSTRpszPath);Determinesifafileexists.—经检测,该函数可以检测文件或目录是否存在!RemarksThi

    2022年6月30日
    39
  • JSP include参数的中文乱码问题

    JSP include参数的中文乱码问题最近在做jsp页面时,需要在a.jsp页面中,include一个b.jsp文件。a.jsp传递给b.jsp的参数是动态加载的,可能是中文。当出现中文时,b.jsp就会显示乱码。a.jsp文件如下所示:Stringsearchword=(String)request.getAttribute(“searchword”);   “/>b.jsp文件如下所示:

    2022年7月13日
    14
  • 彻底禁止Win10自动更新工具Windows Update Blocker v1.5 汉化版

    彻底禁止Win10自动更新工具Windows Update Blocker v1.5 汉化版以往的Windows10系统我们还可以通过禁止更新服务,设置一些本地组策略来禁止Windows系统的更新,但现在的Windows好像越来越流行更新了,一些简单的禁止完全没用,依旧会自动检查更新!一款你需要的彻底禁止Win10自动更新的工具它来了,WindowsUpdateBlocker是一款免费软件,只需一键,即可帮助您完全禁用或启用Windows系统上的自动更新。使用起来超级…

    2022年6月4日
    132
  • c++实现strstr函数_C语言字符串数组

    c++实现strstr函数_C语言字符串数组自己实现C语言中的strstr函数,采用字符一个一个进行匹配,如果不等,则从下一个位置进行匹配。/*strstr实现*/char*mystrstr(constchar*dest,constchar*src){char*tdest=dest;char*tsrc=src;while(*tdest){char*flag=tdest;//设置标志位,方便回滚。while…

    2022年10月13日
    5

发表回复

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

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