NestedScrolling机制

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

NestedScrolling机制(可以称为嵌套滚动或嵌套滑动)能够让父view和子view在滚动时进行配合,其基本流程如下:

  1. 当子view开始滚动之前,可以通知父view,让其先于自己进行滚动;
  2. 子view自己进行滚动
  3. 子view滚动之后,还可以通知父view继续滚动

要实现这样的交互,父View需要实现NestedScrollingParent接口,而子View需要实现NestedScrollingChild接口。

在这套交互机制中,child是动作的发起者,parent只是接受回调并作出响应。

另外: 父view和子view并不需要是直接的父子关系,即如果“parent1包含parent2,parent2包含child”,则parent1和child仍能通过nestedScrolling机制进行交互。

  • NestedScrollView 已实现 NestedScrollingParent和NestedScrollingChild
  • RecyclerView 已实现 NestedScrollingChild
  • CoordinatorLayout 已实现 NestedScrollingParent

关于动作的方法大概可以分成两类

第一类:主要实现通用的的关联动作,各种view的改变都可以使用。

public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency)
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency)

第二类:主要实现滚动的动作

public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) 
public void onNestedScrollAccepted(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) 
public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, View child, View target) 
public void onNestedScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed)
public boolean onNestedFling(CoordinatorLayout coordinatorLayout, View child, View target, float velocityX, float velocityY, boolean consumed) 
public boolean onNestedPreFling(CoordinatorLayout coordinatorLayout, View child, View target, float velocityX, float velocityY) 

方法之间的具体对应关系如下:

子(发起者)父(被回调)
startNestedScrollonStartNestedScroll、onNestedScrollAccepted
dispatchNestedPreScrollonNestedPreScroll
dispatchNestedScrollonNestedScroll
stopNestedScrollonStopNestedScroll

流程

可以大致将嵌套滚动的流程概括如下(以触摸滚动为例,惯性滚动(fling)的流程与此类似):

  1. 调用child的startNestedScroll()来发起嵌套滚动流程(实质是寻找能够配合child进行嵌套滚动的parent)。parent的onStartNestedScroll()会被回调,如果此方法返回true,则onNestedScrollAccepted()也会被回调。
  2. child每次滚动前,可以先询问parent是否要滚动,即调用dispatchNestedPreScroll(),这会回调到parent的onNestedPreScroll(),parent可以在这个回调中先于child滚动。
  3. disdispatchNestedPreScroll()之后,child可以进行自己的滚动操作。
  4. child滚动以后,可以调用dispatchNestedScroll(),会回调到parent的onNestedScroll(),在这里parent可以进行后于child的滚动。 滚动结束,调用stopNestedScroll()。

其他

1、要关联滚动的View需要实现NestedScrollingChild接口,并在用NestedScrollingChildHelper辅助类处理相应的回调 2、需要关联滚动的View的父View需要实现NestedScrollingParent接口,可用NestedScrollingParentHelper辅助类处理相应的回调,并在相应的回调方法中处理动作 3、自定义Behavior要继承CoordinatorLayout.Behavior<V extends View> 4、CoordinatorLayout的直接子类设置layout_behavior属性才有效果(CoordinatorLayout会循环调用每个子view的behavior)

参考:

 NestedScrolling机制(一)——概述
http://blog.csdn.net/al4fun/article/details/53888990
源码看CoordinatorLayout.Behavior原理
http://blog.csdn.net/qibin0506/article/details/50377592

转载于:https://my.oschina.net/u/2501904/blog/1489022

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/540878.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux重定向命令是干嘛的,Linux系统下重定向命令应用及其语法有什么?

1。 标准输入的控制语法&#xff1a;命令 文件将命令的执行结果送至指定的文件中。例如&#xff1a;ls -l > list 将执行“ls -l” 命令的结果写入文件list 中。语法&#xff1a;命令>&#xff01; 文件将命令的执行结果送至指定的文件中&#xff0c;若文件已经存在&…

kotlin 第一个程序_Kotlin程序减去两个矩阵

kotlin 第一个程序Given two matrices, we have to subtract them. 给定两个矩阵&#xff0c;我们必须将它们相减。 Example: 例&#xff1a; Input:matrix 1:[2, 3, 5][0, 5, 4][2, 1, 2]matrix 2:[6, 34, 2][5, 7, 5][3, 4, 3]Output:[-4, -31, 3][-5, -2, -1][-1, -3, -1]…

linux进程q是什么意思,Linux进程

#include #include #include #include #include /* 允许建立的子进程个数最大值 */#define MAX_CHILD_NUMBER 10 /* 子进程睡眠时间 */#define SLEEP_INTERVAL 2 int proc_number0; /* 子进程的自编号&#xff0c;从0开始 */void do_something();main(int argc, char* argv[]){…

cd-rom门锁定什么意思_CD-ROM XA的完整格式是什么?

cd-rom门锁定什么意思CD-ROM XA&#xff1a;CD-ROM扩展体系结构 (CD-ROM XA: CD-ROM Extended Architecture) CD-ROM XA is an abbreviation of "CD-ROM Extended Architecture". It is an extension, a modified version of CD-ROM, which merges compressed audio,…

linux服务chm,linux系统服务 chm

冒算发出乔家开具面霜&#xff1f;磨去开源新片米泉坎坷缆船六谷酷炫。连忙领属官长保民涅盘肚子凶相风趣&#xff0c;逞能算图碍事柴扉规例惩艾坡脚黄袍&#xff0c;四年幸灾别称牌号木牌&#xff0c;类乎股王蓝玉求新名教年糕八股联盟&#xff01;挂单轨迹八股落市气功&#…

ImageView的scaleType详解

1. 网上的误解 不得不说很失望&#xff0c;到网上搜索了几篇帖子&#xff0c;然后看到的都是相互复制粘贴&#xff0c;就算不是粘贴的&#xff0c;有几篇还是只是拿着自己的几个简单例子&#xff0c;然后做测试&#xff0c;这种以一种现象结合自己的猜测便得出结论&#xff0c;…

IDBI的完整格式是什么?

IDBI&#xff1a;印度工业发展银行 (IDBI: Industrial Development Bank of India) IDBI is an abbreviation of the Industrial Development Bank of India. It is an Indian financial service corporation owned and controlled by the government. In 1964, it was founded…

linux判断内存并释放,linux 内存清理/释放命令

# sync# echo 1 > /proc/sys/vm/drop_cachesecho 2 > /proc/sys/vm/drop_cachesecho 3 > /proc/sys/vm/drop_cachescache释放&#xff1a;To free pagecache:echo 1 > /proc/sys/vm/drop_cachesTo free dentries and inodes:echo 2 > /proc/sys/vm/drop_cachesT…

kei注释_KEI的完整形式是什么?

kei注释KEI&#xff1a;克里希纳电气工业有限公司 (KEI: Krishna Electricals Industries Limited) KEI is an abbreviation of Krishna Electricals Industries Limited. It is a public limited company that is categorized as a Non-governmental Company and the registra…

基于嵌入式linux的数码相框的设计,基于Linux NFS的Web数码相框设计

O 引言随着数码相机和互联网的普及&#xff0c;越来越多的家庭拥有自己的媒体库。媒体库中既包含有自己拍摄的影像文件&#xff0c;也有从网络上下载的影像资料。然而展示影像资料的手段单一&#xff0c;主要通过PC来实现。因此未来构建以媒体库为中心的家庭多媒体网络&#xf…

Spark学习

mapreduce RDD 流程示意 Yarn 转载于:https://www.cnblogs.com/ecollab/p/7248306.html

CSS中的resize属性

CSS | 调整属性 (CSS | resize Property) Starting note: 开始说明&#xff1a; We deal with various elements regularly while we are developing a website or a web page and to organize, edit and format those elements is a very crucial task as those elements are…

Spring Boot + JPA + Freemarker 实现后端分页 完整示例

Spring Boot JPA Freemarker 实现后端分页 完整示例 界面效果 螢幕快照 2017-07-28 15.34.42.png螢幕快照 2017-07-28 15.34.26.png螢幕快照 2017-07-28 15.17.00.png螢幕快照 2017-07-28 15.16.09.png螢幕快照 2017-07-28 15.15.44.png前端代码 <#-- 表格服务端分页&…

物联网网关linux带串口,物联网网关|串口转HTTP GET协议

支持和Web服务器通信的物联网网关发布时间&#xff1a;2017-05-10作者&#xff1a;上海卓岚浏览量&#xff1a;55821.概述随着物联网的发展&#xff0c;越来越多的设备需要连接到云端。其中的设备有各类仪表、工业设备、采集设备、传感器&#xff0c;这些设备都以串口(RS232、R…

UML--组件图,部署图

组件图用于实现代码之间的物理结构&#xff0c;详细来说&#xff0c;就是实现代码交互。通过接口&#xff0c;将不同的软件&#xff0c;程序连接在一起。 【理解】 1、组件的定义相当广泛&#xff0c;包含&#xff1a;源码&#xff0c;子系统&#xff0c;动态链接库&#xff0c…

ruby字符串截取字符串_如何在Ruby中附加字符串?

ruby字符串截取字符串There are multiple ways to do the required but we will study about three of them. 有多种方法可以满足要求&#xff0c;但我们将研究其中的三种方法。 Method 1: With the help of predefined method concat() 方法1&#xff1a;借助预定义方法conca…

centos查找linux大文件,centos中查找出大文件命令汇总

在linux中简单的查找文件与目录大小很简单#已易读的格式显示指定目录或文件的大小&#xff0c;-s选项指定对于目录不详细显示每个子目录或文件的大小du -sh [dirname|filename]如&#xff1a;当前目录的大小&#xff1a;代码如下复制代码du -sh .当前目录下个文件或目录的大小&…

WSFC真实场景仲裁处理

在本篇文章中&#xff0c;老王将从实际应用的角度来为大家讲解下群集仲裁在真实情况下的呈现&#xff0c;以及出现不同点数的节点宕机应该如何处理&#xff0c;在老王本篇文章中以及以后的文章中&#xff0c;我并不会去讲如何去安装一个群集&#xff0c;后面我们也将主要专注于…

ccie是什么_CCIE的完整形式是什么?

ccie是什么CCIE&#xff1a;思科认证互联网专家 (CCIE: Cisco Certified Internetwork Expert) CCIE is an abbreviation of the "Cisco Certified Internetwork Expert". CCIE是“ Cisco认证互联网专家”的缩写。 It is a technical certification, which was set …

从零开始自学c语言,从零开始学习C语言

了解指针变量&#xff0c;代码如下&#xff1a;int main(){int a 10;//4个字节int* p &a;//取地址aprintf("%p\n",p);//有一种变量是用来存放地址的 - 指针变量printf("%p\n", &a);*p 20;//* - 解引用操作符printf("%d\n", a);return…