美文网首页
View事件的传递体系——嵌套滑动

View事件的传递体系——嵌套滑动

作者: 丸子哒哒哒 | 来源:发表于2019-05-13 15:59 被阅读0次

    难点:当子控件消费了事件,那么父控件就不会再有机会处理事件

    原理:子控件在接收到滑动一段距离的请求时,先询问爸爸是否要滑动,如果爸爸滑动了一部分,就通知子控件消耗的距离,子控件只能处理剩下的距离,处理结束之火,再把剩余的滑动距离传给父控件

    兼容性问题:

    SDK 21 以下:需要去实现 v4包里面的NestedScrollingChild,或者NestedScrollingParent
    SDK 21及以上,View以及ViewGroup新增了这些方法
    NestedScrollingChild NestedScrollingParent ViewGroup View
    setNestedScrollingEnabled setNestedScrollingEnabled
    isNestedScrollingEnabled onNestedScrollAccepted onNestedScrollAccepted isNestedScrollingEnabled
    startNestedScroll onStartNestedScroll onStartNestedScroll startNestedScroll
    stopNestedScroll onStopNestedScroll onStopNestedScroll stopNestedScroll
    hasNestedScrollingParent getNestedScrollAxes getNestedScrollAxes hasNestedScrollingParent
    dispatchNestedScroll onNestedScroll onNestedScroll dispatchNestedScroll
    dispatchNestedPreScroll onNestedPreScroll onNestedPreScroll dispatchNestedPreScroll
    dispatchNestedFling onNestedFling onNestedFling dispatchNestedFling
    dispatchNestedFling onNestedPreFling onNestedPreFling dispatchNestedPreFling

    默认处理逻辑:
    本身不支持滑动的控件,即使有嵌套滑动的相关方法也不能进行嵌套滑动,所以要让控件支持嵌套滑动,那么要满足:
    1.控件类具有嵌套滑动的相关方法,要买仅支持21之后,要么实现对应的接口
    2.控件要在合适的位置主动调起嵌套滑动方法

    相关文章

      网友评论

          本文标题:View事件的传递体系——嵌套滑动

          本文链接:https://www.haomeiwen.com/subject/wicraqtx.html