NestedScrollingParent是一個接口,實(shí)現(xiàn)它需要實(shí)現(xiàn)如下方法:
//該方法決定了當(dāng)前控件是否能接收到其內(nèi)部View(非并非是直接子View)滑動時的參數(shù);假設(shè)你只涉及到縱向滑動,這里可以根據(jù)nestedScrollAxes這個參數(shù),進(jìn)行縱向判斷。
// 參數(shù)child:當(dāng)前實(shí)現(xiàn)`NestedScrollingParent`的ViewParent包含觸發(fā)嵌套滾動的直接子view對象
// 參數(shù)target:觸發(fā)嵌套滾動的view (在這里如果不涉及多層嵌套的話,child和target)是相同的
// 參數(shù)nestedScrollAxes:就是嵌套滾動的滾動方向了.垂直或水平方法
//返回參數(shù)代表當(dāng)前ViewParent是否可以觸發(fā)嵌套滾動操作
//CoordiantorLayout的實(shí)現(xiàn)上是交由子View的Behavior來決定,并回調(diào)了各個acceptNestedScroll方法,告訴它們處理結(jié)果
public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes);
//l該方法的會傳入內(nèi)部View移動的dx,dy,如果你需要消耗一定的dx,dy,就通過最后一個參數(shù)consumed進(jìn)行指定,例如我要消耗一半的dy,就可以寫consumed[1]=dy/2
//onStartNestedScroll返回true才會觸發(fā)這個方法
//參數(shù)和onStartNestedScroll方法一樣
//按照官方文檔的指示,CoordiantorLayout有一個NestedScrollingParentHelper類型的成員變量,并把這個方法交由它處理
//同樣,這里也是需要CoordiantorLayout遍歷子View,對可以嵌套滾動的子View回調(diào)Behavior#onNestedScrollAccepted方法
public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes);
public void onNestedScroll(View target, int dxConsumed, int dyConsumed,
int dxUnconsumed, int dyUnconsumed);
public void onNestedPreScroll(View target, int dx, int dy, int[] consumed);
public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed);
//你可以捕獲對內(nèi)部View的fling事件,如果return true則表示攔截掉內(nèi)部View的事
public boolean onNestedPreFling(View target, float velocityX, float velocityY);
public int getNestedScrollAxes();