NestedScrollingParent 和NestedScrollingChild

来源:互联网 发布:金俊用的什么软件 编辑:程序博客网 时间:2024/05/22 00:00


在5.0以上 有些滑动view实现了NestedScrollingParent  和NestedScrollingChild

CoordinatorLayout
里面的LayoutParams 有着一个
mBehavior以下是
CoordinatorLayout 源码一部分

@Overridepublic void onNestedPreScroll(View target, int dx, int dy, int[] consumed) {    int xConsumed = 0;    int yConsumed = 0;    boolean accepted = false;    final int childCount = getChildCount();    for (int i = 0; i < childCount; i++) {        final View view = getChildAt(i);        if (view.getVisibility() == GONE) {            // If the child is GONE, skip...            continue;        }       //这个LayoutParams是CoordinatorLayout.layoutparams      final LayoutParams lp = (LayoutParams) view.getLayoutParams();        if (!lp.isNestedScrollAccepted()) {            continue;        }        final Behavior viewBehavior = lp.getBehavior();        if (viewBehavior != null) {            mTempIntPair[0] = mTempIntPair[1] = 0;//滑动的回调 viewBehavior.onNestedPreScroll(this, view, target, dx, dy, mTempIntPair);            xConsumed = dx > 0 ? Math.max(xConsumed, mTempIntPair[0])                    : Math.min(xConsumed, mTempIntPair[0]);            yConsumed = dy > 0 ? Math.max(yConsumed, mTempIntPair[1])                    : Math.min(yConsumed, mTempIntPair[1]);            accepted = true;        }    }    consumed[0] = xConsumed;    consumed[1] = yConsumed;    if (accepted) {        onChildViewsChanged(EVENT_NESTED_SCROLL);    }}
也就是说 在滑动的时候多了一些不同状态下的滑动

https://segmentfault.com/a/1190000002873657

https://race604.com/flyrefresh/

https://race604.com/android-nested-scrolling/

http://blog.csdn.net/feizhixuan46789/article/details/50520197

http://blog.csdn.net/diaotai/article/details/52217077

http://www.jianshu.com/p/ed2852eff92e

https://www.zhihu.com/question/27775923


0 0