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


相关推荐

  • 在ubuntu系统下安装python

    在ubuntu系统下安装python

    2021年10月6日
    72
  • 调用python-can库使用周立功CAN接口卡发送数据「建议收藏」

    调用python-can库使用周立功CAN接口卡发送数据「建议收藏」查阅python-can文档,知晓其支持部分周立功CAN接口卡,故写例程验证数据的发送。另外,使用的python版本为3.4,在安装python-can时提示找不到windows-curses对应版本的安装包,故在python-can的setup.py中,取消了windows-curses的安装依赖。代码如下(ControlCAN.dll需放置在相同路径下):from__future__importprint_functionimportplatformimportcandefsen

    2022年6月21日
    104
  • ConfigurationManager.ConnectionStrings 属性[通俗易懂]

    ConfigurationManager.ConnectionStrings 属性[通俗易懂]publicstaticConnectionStringSettingsCollectionConnectionStrings{get;}App.config1<?xmlversion=”1.0″encoding=”utf-8″?>2<configuration>3<startup>4&lt…

    2022年5月21日
    142
  • BeanUtils.copyProperties 用法

    BeanUtils.copyProperties 用法BeanUtils.copyProperties方法不用操作过多的set/get方法,两个类字段相同的时候我们可以通过此方法来进行复制,如有不想复制的属性则用第三个构造参数来进行,如果你只需要改其中的一个属性或者两个属性没必要重新get/set一边直接复制原来的类,付给新类属性名相同即可赋值。…

    2022年9月1日
    5
  • linux下卸载软件命令行,如何使用Linux中的命令行卸载软件 | MOS86「建议收藏」

    linux下卸载软件命令行,如何使用Linux中的命令行卸载软件 | MOS86「建议收藏」Linux提供了不同的安装软件的方法。您可以使用Ubuntu软件中心从标准Ubuntu软件仓库外部或通过编译源代码安装来自标准Ubuntu软件仓库的软件。但是,如果你需要卸载程序怎么办?如果您使用Ubuntu软件中心从Ubuntu软件仓库安装了软件,您可以使用Ubuntu软件中心来卸载该软件。但是,如果您使用命令行更加舒适,我们将向您显示一个简单的方法来查看系统上安装的内容并卸载程序。相关文章图片…

    2022年9月9日
    4
  • 浅谈Springcloud和Dubbo的区别「建议收藏」

    浅谈Springcloud和Dubbo的区别「建议收藏」最近一段时间不论互联网还是传统行业,凡是涉及信息技术范畴的圈子几乎都在讨论 微服务架构 。近期也看到各大技术社区开始组织一些沙龙和论坛来分享spring Cloud的相关实施经验,这对于最近正在整理SpringCloud相关套件内容与实例应用的我而言,还是有不少激励的。目前,SpringCloud在国内的知名度并不高,在前阵子的求职过程中,与一些互联网公司的架构师、技术VP或者CTO在交流…

    2022年6月7日
    26

发表回复

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

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