public interface NestedScrollingParent
| android.support.v4.view.NestedScrollingParent |
| |
这个接口应该由 ViewGroup子类来实现,它们希望支持由嵌套子视图委托的滚动操作。
实现此接口的类应该创建一个 NestedScrollingParentHelper的最终实例作为字段,并将任何View或ViewGroup方法委托给相同签名的 NestedScrollingParentHelper方法。
查看调用嵌套滚动功能应该始终从相关这么做ViewCompat , ViewGroupCompat或者ViewParentCompat兼容性垫片的静态方法。 这确保了与Android 5.0 Lollipop和更新的嵌套滚动视图的互操作性。
公共方法(Public methods) |
|
|---|---|
abstract int |
getNestedScrollAxes() 为此NestedScrollingParent返回嵌套滚动的当前坐标轴。 |
abstract boolean |
onNestedFling(View target, float velocityX, float velocityY, boolean consumed) 从嵌套滚动中请求投掷。 |
abstract boolean |
onNestedPreFling(View target, float velocityX, float velocityY) 在目标视图消耗它之前,将其反应为嵌套的拖动。 |
abstract void |
onNestedPreScroll(View target, int dx, int dy, int[] consumed) 在目标视图占用滚动的一部分之前,对正在进行的嵌套滚动进行处理。 |
abstract void |
onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) 反应到正在进行的嵌套滚动。 |
abstract void |
onNestedScrollAccepted(View child, View target, int nestedScrollAxes) 响应成功声明嵌套滚动操作。 |
abstract boolean |
onStartNestedScroll(View child, View target, int nestedScrollAxes) 响应启动可嵌套滚动操作的后代视图,并在适当的情况下声明嵌套滚动操作。 |
abstract void |
onStopNestedScroll(View target) 反应到嵌套滚动操作结束。 |
int getNestedScrollAxes ()
为此NestedScrollingParent返回嵌套滚动的当前坐标轴。
返回非 SCROLL_AXIS_NONE之外的 SCROLL_AXIS_NONE当前充当层次结构中一个或多个后代视图的嵌套滚动父级。
| 返回(Returns) | |
|---|---|
int |
Flags indicating the current axes of nested scrolling |
boolean onNestedFling (View target, float velocityX, float velocityY, boolean consumed)
从嵌套滚动中请求投掷。
这种方法表示嵌套滚动的孩子已经检测到适合于一阵子的条件。 通常这意味着触摸滚动以velocity的滚动方向结束,沿滚动轴达到或超过minimum fling velocity 。
如果嵌套的滚动子视图通常会抛出,但它位于其自己的内容的边缘,则可以使用此方法代替该嵌套的滚动父级。 父母可以有选择地消费一下,或者观察孩子的情绪。
| 参数(Parameters) | |
|---|---|
target |
View: View that initiated the nested scroll |
velocityX |
float: Horizontal velocity in pixels per second |
velocityY |
float: Vertical velocity in pixels per second |
consumed |
boolean: true if the child consumed the fling, false otherwise |
| 返回(Returns) | |
|---|---|
boolean |
true if this parent consumed or otherwise reacted to the fling |
boolean onNestedPreFling (View target, float velocityX, float velocityY)
在目标视图消耗它之前,将其反应为嵌套的拖动。
这种方法意味着一个嵌套的滚动孩子已经检测到沿着每个轴具有给定速度的飞掷。 通常这意味着触摸滚动以velocity的滚动方向结束,沿滚动轴满足或超过minimum fling velocity 。
If a nested scrolling parent is consuming motion as part of a pre-scroll, it may be appropriate for it to also consume the pre-fling to complete that same motion. By returning true from this method, the parent indicates that the child should not fling its own internal content as well.
| 参数(Parameters) | |
|---|---|
target |
View: View that initiated the nested scroll |
velocityX |
float: Horizontal velocity in pixels per second |
velocityY |
float: Vertical velocity in pixels per second |
| 返回(Returns) | |
|---|---|
boolean |
true if this parent consumed the fling ahead of the target view |
void onNestedPreScroll (View target, int dx, int dy, int[] consumed)
在目标视图占用滚动的一部分之前,对正在进行的嵌套滚动进行处理。
当经常使用嵌套滚动时,父视图可能希望有机会在嵌套滚动子代之前使用滚动。 一个例子是一个包含可滚动列表的抽屉。 用户将希望能够在列表本身开始滚动之前将列表完全滚动到视图中。
onNestedPreScroll当嵌套滚动孩子调用被称为dispatchNestedPreScroll(int, int, int[], int[]) 。 该实现应报告dx,dy所报告的滚动像素是如何在consumed阵列中消耗的。 索引0对应于dx,索引1对应于dy。 该参数永远不会为空。 消耗[0]和消耗[1]的初始值将始终为0。
| 参数(Parameters) | |
|---|---|
target |
View: View that initiated the nested scroll |
dx |
int: Horizontal scroll distance in pixels |
dy |
int: Vertical scroll distance in pixels |
consumed |
int: Output. The horizontal and vertical scroll distance consumed by this parent |
void onNestedScroll (View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)
反应到正在进行的嵌套滚动。
当ViewParent的当前嵌套滚动子视图调度一个嵌套滚动事件时,将调用此方法。 要接收对此方法的调用,ViewParent必须先前返回true才能拨打onStartNestedScroll(View, View, int) 。
将滚动距离的消耗部分和未消耗部分都报告给ViewParent。 例如,实现可以选择使用消费部分来匹配或追踪多个子元素的滚动位置。 未消耗部分可用于允许连续拖动多个滚动或可拖动元素,诸如在垂直抽屉内滚动列表,其中抽屉在达到内部滚动内容的边缘时开始拖动。
| 参数(Parameters) | |
|---|---|
target |
View: The descendent view controlling the nested scroll |
dxConsumed |
int: Horizontal scroll distance in pixels already consumed by target |
dyConsumed |
int: Vertical scroll distance in pixels already consumed by target |
dxUnconsumed |
int: Horizontal scroll distance in pixels not consumed by target |
dyUnconsumed |
int: Vertical scroll distance in pixels not consumed by target |
void onNestedScrollAccepted (View child, View target, int nestedScrollAxes)
响应成功声明嵌套滚动操作。
此方法将在onStartNestedScroll返回true后onStartNestedScroll 。 它为视图及其超类为嵌套滚动执行初始配置提供了机会。 如果存在这种方法的实现,则应始终调用其超类的此方法的实现。
| 参数(Parameters) | |
|---|---|
child |
View: Direct child of this ViewParent containing target |
target |
View: View that initiated the nested scroll |
nestedScrollAxes |
int: Flags consisting of SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_VERTICAL or both |
boolean onStartNestedScroll (View child, View target, int nestedScrollAxes)
响应启动可嵌套滚动操作的后代视图,并在适当的情况下声明嵌套滚动操作。
这个方法将被调用以响应调用startNestedScroll(View, int)的后代视图。 视图层次结构中的每个父母将有机会通过返回true来响应和声明嵌套滚动操作。
ViewParent实现可能会重写此方法,以指示视图何时愿意支持即将开始的嵌套滚动操作。 如果它返回true,则在正在进行滚动操作期间,此ViewParent将成为目标视图的嵌套滚动父级。 当嵌套滚动完成后,此ViewParent将收到对onStopNestedScroll(View)的呼叫。
| 参数(Parameters) | |
|---|---|
child |
View: Direct child of this ViewParent containing target |
target |
View: View that initiated the nested scroll |
nestedScrollAxes |
int: Flags consisting of SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_VERTICAL or both |
| 返回(Returns) | |
|---|---|
boolean |
true if this ViewParent accepts the nested scroll operation |
void onStopNestedScroll (View target)
反应到嵌套滚动操作结束。
在嵌套滚动操作后执行清理。 当嵌套滚动停止时,将调用此方法,例如,当嵌套触摸滚动以ACTION_UP或ACTION_CANCEL事件结束时。 如果存在这种方法的实现,则应始终调用其超类的此方法的实现。
| 参数(Parameters) | |
|---|---|
target |
View: View that initiated the nested scroll |