关于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滑动冲突,可以很流畅的滑动 的相关文章

  • 在android 10中设置通知操作的背景颜色

    我已经做到了这一点图片链接 https i stack imgur com o0Cel jpg通过关注这篇文章https medium com dcostalloyd90 show incoming voip call notificati
  • PickContact 需要 android.permission.READ_CONTACTS 或 grantUriPermission()

    首先一些信息 我首先在 Cordova 中创建了该应用程序 请参阅Cordova 权限需要 android permission READ CONTACTS 或 grantUriPermission https stackoverflow
  • ListView 滚动时隐藏和显示浮动按钮

    我正在我的应用程序中创建一个 listView 和一个浮动按钮 我希望根据滚动状态实现隐藏和返回的效果 当 的时候ListView滚动时按钮隐藏得很好 但是当滚动停止时按钮不会返回到其初始位置 有任何想法吗 My Code public c
  • Android问题:Eclipse找不到ADB.exe

    首先 我知道这个问题之前已经被问过 即 在我的工具文件夹中找不到 adb exe https stackoverflow com questions 4659014 could not find adb exe on my tools fo
  • Android模拟器收不到推送通知

    我在谷歌云上使用推送通知 但是由于某种原因我无法在模拟器上接收推送通知 然而 当我在真实设备上测试时 同一个应用程序确实会收到通知 有其他人遇到过这个问题或找到解决方案吗 模拟设备具有网络访问权限 并且与真实设备具有相同的 Android
  • 如何在Android中设置对话框的图标

    我想在Android中自定义一个对话框 我知道如何设置对话框的标题 dialog setTitle O message 现在我想在标题前面设置图标 我怎样才能实现这个目标 Dialog dialog dialog new Dialog th
  • 如何在 jetpack compose 中预览对话框?

    我有这个代码 Composable fun SomeDialog Dialog onDismissRequest properties DialogProperties Preview showBackground true Composa
  • 如何在没有 Google Play 服务的情况下设置 Android 模拟器

    一位客户要求我制作一个应用程序版本 以便在没有 Google Play 服务的设备上运行 有什么方法可以告诉 Android 模拟器在不使用 GPS 的情况下运行应用程序吗 然后我可以测试代码以确保它可以在客户端设备上运行 使用不包含 go
  • 从通用对象访问字段变量

    我有两节课ClassOne and ClassTwo 更新公共字段data i e public class ClassOne public byte data new byte 10 Thread that updates data an
  • 减少 android studio 2.1 构建时间

    我之前使用的是 android studio 1 5 刚刚升级到 2 1 但是更新后我的构建花费了更多时间 从 15 秒到现在 2 分钟 我已经尝试过的事情如上所述 在 设置 中启用离线工作 org gradle daemon true o
  • 使用 sdk 3.0 在 Facebook 墙上发布

    我试图在由其 ID 定义的用户墙上发布一条消息 但作为响应 我收到错误 未知方法 我的代码是 final Bundle params new Bundle params putByteArray message Test getBytes
  • 改造2:使用json对象发送文件

    我在请求正文中发送对象 如下所示 title test description test images POST create data Call
  • Android 中的弹出消息

    我正在开发一个应用程序 我想创建一条弹出消息 在我们不关闭时该消息将保持稳定 我想要一些教程来帮助我制作警报对话框 提前致谢 我认为您正在搜索 对话框 框 从而可以向用户显示警报消息 确认消息等 欲了解更多信息 请参阅此 http deve
  • 如何从 Android 应用程序调试共享库 [单独的项目]

    我正在开发一个 Android 应用程序并在项目中使用密集的 C 代码 首先 我将c 源代码放入项目中 并使用以下指南在Android应用程序中具有本机调试的NDK功能 http tools android com recent using
  • Android 拍摄后画质低

    我有一个触发图像捕获的按钮 private void capturePicture if ActivityCompat checkSelfPermission getContext Manifest permission CAMERA Pa
  • 如何从代码中检测 Android 设备上的双核 cpu?

    我遇到了一个似乎仅影响双核的问题Android设备运行Android 2 3 姜饼 或更大 我想就这个问题进行一次对话 但仅限于符合该标准的用户 我知道如何检查OS级别 但还没有找到任何可以明确告诉我该设备正在使用多核的信息 有任何想法吗
  • Android Wear Preview 未连接到 Wear Emulator

    我正在尝试为 Google Wear 设置开发环境并遵循 Google 的指示 http developer android com training wearables apps creating html但一旦我设置了端口转发 adb
  • XML 渲染错误 Android 预览 N

    更新后我已将 android SDK 更新为 android Preview N 但收到此 xml 渲染错误 单击详细信息后 它显示以下堆栈跟踪如何避免这种情况 org jetbrains android uipreview Renderi
  • Android:使用 ObjectAnimator 平移具有视图尺寸小数值的视图

    看来旧的视图动画 translate scale等 不再被接受AnimationInflater 至少截至 ICS 而言 我在 4 0 4 中阅读了它的代码 它明确只需要 XML 元素set objectAnimator animator
  • android中使用xml的新自定义字体方法

    随着 android 发布 O 预览版 添加了一个新功能 称为xml 中的字体 它很容易实现 但我没有什么疑问 让我首先添加最好的方法1 右键单击资源文件夹并前往新建 gt Android 资源目录 新的出现资源目录窗口 2 在资源类型列表

随机推荐

  • 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的时候