NestedScrollingChild和NestedScrollingParent
来源:互联网 发布:阿里云dns解析 编辑:程序博客网 时间:2024/05/18 03:02
NestedScrollingChild和NestedScrollingParent
记录在学习嵌套滑动中遇到的接口和使用方法。
滑动动作是 Child 主动发起,Parent 就收滑动回调并作出响应。
NestedScrollingChild接口的实现,基本上就是调用 Helper(NestedScrollingChildHelper) 类的对应的函数即可,因为 Helper 类中已经实现好了 Child 和 Parent 交互的逻辑。
准备工作:
当Child要滑动的时候,调用startNestedScroll()方法,通过Helper去通知Parent,此时Parent调用了onStartNestedScroll(),并返回true同意Child一同滑动的请求。随后,Parent调用onNestedScrollAccepted(),来做接受滑动且滑动之前的准备工作,可以直接使用Helper(NestedScrollingParentHelper)类帮我们做处理。
滑动:
每次滑动前,Child首先调用dispatchNestedPreScroll()方法来询问Parent是否需要先于Child滑动,与之对应的是Parent的onNestedPreScroll()方法,在这个方法中,Parent可以做处理,拦截Child自身的滑动,并先于Child滑动。
如果Parent不需要先于Child滑动,Child继续调用dispatchNestedScroll(),对应到Parent的onNestedScroll()方法,这时Parent是在Child滑动并处理完事情后再做处理。
上面两种处理方法都是通过Parent消费滑动距离来处理滑动事件,即给[]consumed赋值,该值是Parent滑动的距离,consumed[0]是x轴,consumed[1]是y轴。
滑动结束后,Parent调用onStopNestedScroll()结束本次滑动。
滑行:
原理和滑动差不多,在滑行之前,Child调用dispatchNestedPreFling(),并通过Helper通知Parent要滑行了,询问Parent要不要在onNestedPreFling()中先行处理Fling事件。
**补充笔记
RecyclerView获取滑动距离
只限于使用LinearLayoutManager的时候
public int getScollYDistance() { LinearLayoutManager layoutManager = (LinearLayoutManager) this.getLayoutManager(); int position = layoutManager.findFirstVisibleItemPosition(); View firstVisiableChildView = layoutManager.findViewByPosition(position); int itemHeight = firstVisiableChildView.getHeight(); return (position) * itemHeight - firstVisiableChildView.getTop(); }
- NestedScrollingChild和NestedScrollingParent
- NestedScrollingParent 和NestedScrollingChild
- Android中的NestedScrollingParent和NestedScrollingChild分析
- Android中的NestedScrollingParent和NestedScrollingChild分析
- NestedScrollingParent, NestedScrollingChild 详解
- NestedScrollingParent, NestedScrollingChild 详解
- NestedScrollingParent, NestedScrollingChild 详解
- NestedScrollingParent, NestedScrollingChild 详解
- NestedScrollingChild NestedScrollingParent API的粗略中文解释
- 从NestedScrollingChild、NestedScrollingParent源码分析嵌套滑动机制
- Android-NestedScrollingParent, NestedScrollingChild父子View 间 的 嵌套滑动
- 实现嵌套滑动——NestedScrollingParent与NestedScrollingChild接口及其实现
- NestedScrollingParent
- WebView 实现 NestedScrollingChild
- 仿NestedScrollingParent嵌套滑动
- RecyclerView的NestedScrollingParent
- Android 自定义WebView 实现 NestedScrollingChild
- Android 自定义WebView 实现 NestedScrollingChild
- Qt技巧:多线程实现方法
- 树莓派技巧:树莓派截图方法
- 建站技巧:WordPress主题制作全过程(二):主题文件构成
- JavaScript学习笔记1-环境准备
- Qt技巧:Qt常用数据类型转换
- NestedScrollingChild和NestedScrollingParent
- 【Qt项目】串口通信:PLC对LPC的音量控制
- plsql程序设计详解(一)
- Android查看某个App功能是Native实现还是Webview实现
- 建站技巧:WordPress报错 Error500:“WordPress Internal Server Error”
- Qt技巧:获取QTextEdit文本内容
- 【Qt项目】USBHID:读取数据
- DOM Element类节点
- Qt技巧:加载第三方API