https://github.com/android/views-widgets-samples/blob/master/ConstraintLayoutExamples/motionlayout/src/main/java/com/google/androidstudio/motionlayoutexample/utils/TouchFrameLayout.java
基本上Android開始把可以Scrolling的View用一個叫ViewParentCompat的東西作協調器,然後可以透過viewparentcompat中定義的parent child來互相傳達scrolling event
public class RecyclerView extends ViewGroup implements ScrollingView ,NestedScrollingChild2, NestedScrollingChild3 {
從RecyclerView中,是個child的角色,然後自己scrolling時,往外丟出scrolling event
RecyclerView.class
@Overridepublic boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow, int type) { return getScrollingChildHelper().dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow, type);}
ViewParentCompat如果是個Parent的角色,自然就會接收到scrolling event
ViewParentCompat.class
if (parent instanceof NestedScrollingParent2) { // First try the NestedScrollingParent2 API ((NestedScrollingParent2) parent).onNestedPreScroll(target, dx, dy, consumed, type);}
那麼Parent就會收到callback onNestedPreScroll(xxxx
@Overridepublic void onNestedPreScroll(@NonNull View target, int dx, int dy, @NonNull int[] consumed, int type) { getMotionLayout().onNestedPreScroll(target, dx, dy, consumed, type);}
接著把所有callback event導入MotionLayout,看起來就可以吳鳳接軌。
Beautiful, isn't it.