关于ScrollView嵌套多个RecyclerView滑动冲突,可以很流畅的滑动

2023-11-18

首先不建议过多的嵌套,可以采取其他方式替换

当ScrollIView内部只有一个RecyclerView的时候

 

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <!--其它的View-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/header_view"
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:gravity="center"
                android:text="这个是RecyclerView"
                android:textColor="#000"
                android:textSize="24sp"/>
        </LinearLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />
    </LinearLayout>
</ScrollView>

OneRecyclerView.gif

当ScrollIView内部有多个RecyclerView的时候

 

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    android:id="@+id/scroll_view"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <!--其它的View-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/header_view"
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:gravity="center"
                android:text="这个是RecyclerView"
                android:textColor="#000"
                android:textSize="24sp"/>

        </LinearLayout>


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:descendantFocusability="blocksDescendants"
            android:focusable="true"
            android:focusableInTouchMode="true">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view_one"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:nestedScrollingEnabled="false"
                >

            </android.support.v7.widget.RecyclerView>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:descendantFocusability="blocksDescendants"
            android:focusable="true"
            android:focusableInTouchMode="true">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view_two"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="30dp"
                android:layout_marginTop="30dp"
                android:nestedScrollingEnabled="false">


            </android.support.v7.widget.RecyclerView>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:descendantFocusability="blocksDescendants"
            android:focusable="true"
            android:focusableInTouchMode="true">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view_three"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:nestedScrollingEnabled="false">


            </android.support.v7.widget.RecyclerView>
        </RelativeLayout>
    </LinearLayout>
</ScrollView>

当ScrollView嵌套多个RecyclerView时设置RecyclerView的android:nestedScrollingEnabled="false",将滑动事件交给父类的ScrollView去处理,并且每个RecyclerView外面包上一层RelativeLayout,设置如下属性,效果展示出下:

 

            android:descendantFocusability="blocksDescendants"
            android:focusable="true"
            android:focusableInTouchMode="true"

MultiRecyclerView.gif

当ScrollIView内部只有一个RecyclerView的时候并且外部嵌套上下拉刷新控件

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">


    <com.scwang.smartrefresh.layout.SmartRefreshLayout
        android:id="@+id/smart_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:srlEnableHeaderTranslationContent="false"
        app:srlEnableLoadmore="true"
        >

        <com.scwang.smartrefresh.header.MaterialHeader
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <ScrollView
            android:id="@+id/scroll_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <!--其它的View-->
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/header_view"
                        android:layout_width="match_parent"
                        android:layout_height="80dp"
                        android:gravity="center"
                        android:text="这个是RecyclerView"
                        android:textColor="#000"
                        android:textSize="24sp"/>

                </LinearLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:descendantFocusability="blocksDescendants"
                    android:focusable="true"
                    android:focusableInTouchMode="true">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler_view"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:nestedScrollingEnabled="false"
                        >

                    </android.support.v7.widget.RecyclerView>
                </RelativeLayout>
            </LinearLayout>
        </ScrollView>

        <com.scwang.smartrefresh.layout.footer.ClassicsFooter
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </com.scwang.smartrefresh.layout.SmartRefreshLayout>

</RelativeLayout>

OneRecyclerViewWithRefresh.gif

当ScrollIView内部有多个RecyclerView的时候并且外部嵌套上下拉刷新控件

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">


    <com.scwang.smartrefresh.layout.SmartRefreshLayout
        android:id="@+id/smart_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:srlEnableHeaderTranslationContent="false"
        app:srlEnableLoadmore="true"
        >

        <com.scwang.smartrefresh.header.MaterialHeader
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <ScrollView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/scroll_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <!--其它的View-->
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/header_view"
                        android:layout_width="match_parent"
                        android:layout_height="80dp"
                        android:gravity="center"
                        android:text="这个是RecyclerView"
                        android:textColor="#000"
                        android:textSize="24sp"/>

                </LinearLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:descendantFocusability="blocksDescendants"
                    android:focusable="true"
                    android:focusableInTouchMode="true">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler_view_one"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:nestedScrollingEnabled="false"
                        >

                    </android.support.v7.widget.RecyclerView>
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:descendantFocusability="blocksDescendants"
                    android:focusable="true"
                    android:focusableInTouchMode="true">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler_view_two"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginBottom="30dp"
                        android:layout_marginTop="30dp"
                        android:nestedScrollingEnabled="false">


                    </android.support.v7.widget.RecyclerView>
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:descendantFocusability="blocksDescendants"
                    android:focusable="true"
                    android:focusableInTouchMode="true">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler_view_three"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:nestedScrollingEnabled="false">


                    </android.support.v7.widget.RecyclerView>
                </RelativeLayout>
            </LinearLayout>
        </ScrollView>

        <com.scwang.smartrefresh.layout.footer.ClassicsFooter
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </com.scwang.smartrefresh.layout.SmartRefreshLayout>

</RelativeLayout>

MultiRecyclerViewWithRefresh.gif



 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

关于ScrollView嵌套多个RecyclerView滑动冲突,可以很流畅的滑动 的相关文章

随机推荐

  • SpringBoot实现微信支付,微信扫码支付,Native支付(全网最详细教程)

    1 添加微信支付依赖
  • ICCV、ECCV、CVPR三大国际会议

    目录 前言 一 ICCV ECCV CVPR是什么 1 ICCV 2 ECCV 3 CVPR 二 三大会链接及论文下载链接 前言 作为刚入门CV的新人 有必要记住计算机视觉方面的三大顶级会议 ICCV CVPR ECCV 统称为ICE 与其
  • 【论文翻译】文本语义提取

    摘要 文本文档是存储信息的手段之一 这些文档可以在个人桌面计算机 内部网和Web上找到 因此 有价值的知识以非结构化的形式嵌入 拥有一个可以从文本中提取信息的自动化系统是非常可取的 然而 开发这样一个自动化系统的主要挑战是自然语言并不是没有
  • geth生成钱包地址

    配置Geth 博主是Ubuntu18 04 所以 sudo apt update sudo add apt repository ppa longsleep golang backports sudo apt update sudo apt
  • 宏定义与逻辑运算学习笔记

    宏定义 宏定义又称为宏代换 宏替换 简称 宏 格式 define标识符 字符串 其中的标识符就是所谓的符号常量 也称为 宏名 掌握 宏 概念的关键是 换 即在对相关命令或语句的含义和功能作具体分析之前就要换 例 define PI 3 14
  • Tracy 小笔记 Vue - Vue 数据的响应式原理

    变量如果是对象的话 那么需要给对象先定义好属性 才能响应式 因此需要提前定义好所需的属性 如 info name 11 value 22 添加属性 如果想要再之后添加属性的话还想要响应式的话 有如下两种方式 使用 Vue set 这个可以是
  • errcode = 40163; errmsg = "code been used"(提供一种解决思路)

    最近在做微信开发 就在开发完毕测试的时候 遇到一个大问题 每次新用户进入的时候就报错 错误基本上就是code been used 我去百度了好久 没有找到合适的方案 后来我仔细的看了一下微信开发文档 终于解决了 注 该方法不一定对所有人有效
  • C语言中关键字const、static、volatile的用法分析

    1 const 作为一个程序员 我们看到关键字const时 首先想到的应该是 只读 因为 它要求其所修饰的对象为常量 不可对其修改和二次赋值操作 不能作为左值出现 看几个例子 const int a 同上面的代码行是等价的 都表示一个常整形
  • TCP 、UDP、IP包的最大长度是多少?

    对于UDP协议来说 整个包的最大长度为65535 其中包头长度是65535 20 65515 对于TCP协议来说 整个包的最大长度是由最大传输大小 MSS Maxitum Segment Size 决定 MSS就是TCP数据包每次能够传 输
  • 数据回归算法

    文章目录 效果一览 文章概述 源码设计 参考资料 效果一览 文章概述 数据回归算法 Matlab实现逐步回归预测模型 逐步回归 Stepwise Regression 其基本思想是将变量逐个引入模型 每引入一个预测变量 解释变量 后都要进行
  • 作为一个Java程序员,深入java虚拟机第四版

    第一阶段 架构师筑基必备技能 我觉得 但凡是个成年人应该都清楚扎实的基本功对自己的工作帮助有多重要 从各大招聘网站的招聘要求来看 第一条都明确说明需要扎实的Java基础 因此 一般笔试以及面试的第一轮 对基础的考察是比较多的 其实我发现有很
  • 如何写一个随机洗牌函数

    看到了很多人写得随机洗牌函数 但是感觉写得都不是太好 自己写了一个试试 基本要求 给定一定范围的数比如最大值最小值 min max 在这个之间进行随机洗牌 首先生成一个按min到最大的max的数组a 对数组进行循环 每次随机生成一个要取的下
  • c++ 中ref 和引用的区别

    c 中 本身可以使用 来实现引用 那为什么还会出现ref 呢 ref int f2 int c c cout lt lt in function c lt lt c lt
  • Java基础 (三):LinkedList(含使用方法详解)

    Java LinkedList 链表 Linked list 是一种常见的基础数据结构 是一种线性表 但是并不会按线性的顺序存储数据 而是在每一个节点里存到下一个节点的地址 链表可分为单向链表和双向链表 一个单向链表包含两个值 当前节点的值
  • 放大倍数超5万倍的Memcached DDoS反射攻击,怎么破?

    欢迎大家前往腾讯云 社区 获取更多腾讯海量技术实践干货哦 作者 腾讯游戏云 背景 Memcached攻击创造DDoS攻击流量纪录 近日 利用Memcached服务器实施反射DDoS攻击的事件呈大幅上升趋势 DDoS攻击流量首次过T 引发业界
  • Java实现对数据库的查操作

    查询数据库得到的结果有很大的可能会得到若干条 因此executeQuery 方法的返回值是一个集合 返回类型由ResultSet接收 数据库的增删改操作 在JDBCUtils工具类中对close方法进行方法重载 public static
  • 【Spark NLP】第 7 章:分类和回归

    大家好 我是Sonhhxg 柒 希望你看完之后 能对你有所帮助 不足请指正 共同学习交流 个人主页 Sonhhxg 柒的博客 CSDN博客 欢迎各位 点赞 收藏 留言 系列专栏 机器学习 ML 自然语言处理 NLP 深度学习 DL fore
  • 2.VHDL的基本结构和语法(一)

    目录 1 VHDL基本结构 1 1 实体 Entity 类属说明 端口方向 IN OUT INOUT BUFFER 1 2 结构体 Architecture 1 3 库 程序包的调用 1 4 VHDL语句 1 4 1 并行语句 并行信号赋值
  • web项目读取resource目录下的资源

    本地读取资源文件 1 方式 File file new File src main resources properties basecom properties InputStream in new FileInputStream fil
  • 关于ScrollView嵌套多个RecyclerView滑动冲突,可以很流畅的滑动

    首先不建议过多的嵌套 可以采取其他方式替换 当ScrollIView内部只有一个RecyclerView的时候