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.pswp.cn/news/540878.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540878.shtml
英文地址,請注明出處:http://en.pswp.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…