源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android中NestedScrolling滑动机制详解

  • 时间:2021-02-15 13:34 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android中NestedScrolling滑动机制详解
1,如今NestedScrolling运用到很多地方了,要想好看一点的滑动变换,基本上就是使用这个来完成的,让我们来简单的了解一下。 2,NestedScrolling机制能够让父View和子View在滚动式进行配合,其基本流程如下: [list] [*]当子view开始滚动之前,可以通知父View,让其先于自己进行滚动;[/*] [*]子View自己进行滚动;[/*] [*]子view滚动之后,还可以通知父view继续滚动。[/*] [/list] 而要实现这样的交互机制,首先父view要实现NestedScrollingParent接口,而子View需要实现N恩斯特大S从rollingChild接口,在这套机制中子View是发起者,父view是接受回调并做出响应的。 一下是几个关键的类和接口
//主要接口
NestedScrollingChild
NestedScrollingParent

//帮助类
NestedScrollingChildHelper
NestedScrollingParentHelper 
一些新的系统View已经帮我们实现了以上两个接口,也就是说他们是支持NestedScrolling,例如: NestedScrollView已经实现了NestedScrollingChild和NestedScrollingParent两个接口 RecycleView已经实现了NestedScrollingChild CoordinatorLayout实现了NestedScrollingParent [b]NestedScrollingChild接口[/b]
//开始、停止嵌套滚动

public boolean startNestedScroll(int axes); public void stopNestedScroll();

//触摸滚动相关

public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow);

public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow);

//惯性滚动相关 public boolean dispatchNestedPreFling(float velocityX, float velocityY);

public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed); 
public boolean startNestedScroll(int axes);
开启嵌套滚动流程(实际上是进行了一些嵌套滚动前准备工作)。 当找到了能够配合当前子view进行嵌套滚动的父view时,返回值为true(Returns:true if a cooperative parent was found and nested scrolling has been enabled for the current gesture)。
public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow);
在子view自己进行滚动之前调用此方法,询问父view是否要在子view之前进行滚动。 此方法的前两个参数用于告诉父View此次要滚动的距离;而第三第四个参数用于子view获取父view消费掉的距离和父view位置的偏移量。 第一第二个参数为输入参数,即常规的函数参数,调用函数的时候我们需要为其传递确切的值。而第三第四个参数为输出参数,调用函数时我们只需要传递容器(在这里就是两个数组),在调用结束后,我们就可以从容器中获取函数输出的值。 如果parent消费了一部分或全部距离,则此方法返回true。
[url=http://xiazai.jb51.net/201702/yuanma/MyNestedScrolling_jb51.rar]MyNestedScrolling_jb51.rar[/url] 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部