NestedScrollingParent2 嵌套滚动父类2

Artifact: androidx.core:core
神器:androidx.core:core
Added in 1.1.0 已在 1.1.0 中添加

public interface NestedScrollingParent2 extends NestedScrollingParent

CoordinatorLayout

CoordinatorLayout is a super-powered FrameLayout.

NestedScrollingParent3

This interface should be implemented by ViewGroup subclasses that wish to support scrolling operations delegated by a nested child view.

SwipeRefreshLayout

The SwipeRefreshLayout should be used whenever the user can refresh the contents of a view via a vertical swipe gesture.

CoordinatorLayout

CoordinatorLayout is a super-powered FrameLayout.

MotionLayout

A subclass of ConstraintLayout that supports animating between various states Added in 2.0

NestedScrollView

NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android.

SwipeRefreshLayout

The SwipeRefreshLayout should be used whenever the user can refresh the contents of a view via a vertical swipe gesture.


This interface should be implemented by ViewGroup subclasses that wish to support scrolling operations delegated by a nested child view.
该接口应由希望支持嵌套子视图委托的滚动操作的 ViewGroup 子类实现。

Classes implementing this interface should create a final instance of a NestedScrollingParentHelper as a field and delegate any View or ViewGroup methods to the NestedScrollingParentHelper methods of the same signature.
实现该接口的类应创建一个 NestedScrollingParentHelper 作为字段的最终实例,并将任何 View 或 ViewGroup 方法委托给具有相同签名的 NestedScrollingParentHelper 方法。

Views invoking nested scrolling functionality should always do so from the relevant ViewCompat, ViewGroupCompat or ViewParentCompat compatibility shim static methods. This ensures interoperability with nested scrolling views on all versions of Android.
调用嵌套滚动功能的视图应始终使用相关的 ViewCompatViewGroupCompatViewParentCompat 兼容垫片静态方法。这将确保嵌套滚动视图在所有 Android 版本上的互操作性。

Public methods 公共方法

abstract void
onNestedPreScroll(
    @NonNull View target,
    int dx,
    int dy,
    @NonNull int[] consumed,
    int type
)

React to a nested scroll in progress before the target view consumes a portion of the scroll.
在目标视图消耗掉部分滚动之前,对正在进行的嵌套滚动做出反应。

abstract void
onNestedScroll(
    @NonNull View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int type
)

React to a nested scroll in progress.
对正在进行的嵌套滚动做出反应。

abstract void
onNestedScrollAccepted(
    @NonNull View child,
    @NonNull View target,
    int axes,
    int type
)

React to the successful claiming of a nested scroll operation.
对成功执行嵌套滚动操作做出反应。

abstract boolean
onStartNestedScroll(
    @NonNull View child,
    @NonNull View target,
    int axes,
    int type
)

React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate.
对启动可嵌套滚动操作的后代视图做出反应,并在适当情况下执行嵌套滚动操作。

abstract void
onStopNestedScroll(@NonNull View target, int type)

React to a nested scroll operation ending.
对嵌套滚动操作结束做出反应。

Inherited methods 继承方法

abstract int

Return the current axes of nested scrolling for this NestedScrollingParent.

abstract boolean
onNestedFling(
    @NonNull View target,
    float velocityX,
    float velocityY,
    boolean consumed
)

Request a fling from a nested scroll.

abstract boolean
onNestedPreFling(@NonNull View target, float velocityX, float velocityY)

React to a nested fling before the target view consumes it.

abstract void
onNestedPreScroll(
    @NonNull View target,
    int dx,
    int dy,
    @NonNull int[] consumed
)

React to a nested scroll in progress before the target view consumes a portion of the scroll.

abstract void
onNestedScroll(
    @NonNull View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed
)

React to a nested scroll in progress.

abstract void
onNestedScrollAccepted(@NonNull View child, @NonNull View target, int axes)

React to the successful claiming of a nested scroll operation.

abstract boolean
onStartNestedScroll(@NonNull View child, @NonNull View target, int axes)

React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate.

abstract void

React to a nested scroll operation ending.

Added in 1.1.0 已在 1.1.0 中添加
abstract void onNestedPreScroll(
    @NonNull View target,
    int dx,
    int dy,
    @NonNull int[] consumed,
    int type
)

React to a nested scroll in progress before the target view consumes a portion of the scroll.
在目标视图消耗掉部分滚动之前,对正在进行的嵌套滚动做出反应。

When working with nested scrolling often the parent view may want an opportunity to consume the scroll before the nested scrolling child does. An example of this is a drawer that contains a scrollable list. The user will want to be able to scroll the list fully into view before the list itself begins scrolling.
在处理嵌套滚动时,父视图可能希望有机会在嵌套滚动子视图之前使用滚动。一个包含可滚动列表的抽屉就是一个例子。用户希望能在列表本身开始滚动之前将列表完全滚动到视图中。

onNestedPreScroll is called when a nested scrolling child invokes dispatchNestedPreScroll. The implementation should report how any pixels of the scroll reported by dx, dy were consumed in the consumed array. Index 0 corresponds to dx and index 1 corresponds to dy. This parameter will never be null. Initial values for consumed[0] and consumed[1] will always be 0.
当嵌套滚动子代调用 dispatchNestedPreScroll 时,会调用 onNestedPreScroll 。执行时应报告 dx、dy 所报告的滚动像素在 consumed 数组中的消耗情况。索引 0 对应 dx,索引 1 对应 dy。该参数永远不会为空。consumed[0] 和 consumed[1] 的初始值始终为 0。

Parameters 参数
@NonNull View target

View that initiated the nested scroll
启动嵌套滚动的视图

int dx

Horizontal scroll distance in pixels
水平滚动距离(像素

int dy

Vertical scroll distance in pixels
垂直滚动距离(像素

@NonNull int[] consumed

Output. The horizontal and vertical scroll distance consumed by this parent
输出。该父节点消耗的水平和垂直滚动距离

int type

the type of input which cause this scroll event
引起滚动事件的输入类型

Added in 1.1.0 已在 1.1.0 中添加
abstract void onNestedScroll(
    @NonNull View target,
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int type
)

React to a nested scroll in progress.
对正在进行的嵌套滚动做出反应。

This method will be called when the ViewParent's current nested scrolling child view dispatches a nested scroll event. To receive calls to this method the ViewParent must have previously returned true for a call to onStartNestedScroll.
当 ViewParent 的当前嵌套滚动子视图发出嵌套滚动事件时,该方法将被调用。要接收对该方法的调用,ViewParent 必须在调用 onStartNestedScroll 之前返回 true

Both the consumed and unconsumed portions of the scroll distance are reported to the ViewParent. An implementation may choose to use the consumed portion to match or chase scroll position of multiple child elements, for example. The unconsumed portion may be used to allow continuous dragging of multiple scrolling or draggable elements, such as scrolling a list within a vertical drawer where the drawer begins dragging once the edge of inner scrolling content is reached.
滚动距离的已消耗部分和未消耗部分都会报告给 ViewParent。例如,实施时可选择使用已消耗部分来匹配或追逐多个子元素的滚动位置。未消耗部分可用于连续拖动多个滚动或可拖动元素,例如在垂直抽屉中滚动列表,一旦到达内部滚动内容的边缘,抽屉就会开始拖动。

Parameters 参数
@NonNull View target

The descendent view controlling the nested scroll
控制嵌套滚动的后代视图

int dxConsumed

Horizontal scroll distance in pixels already consumed by target
水平滚动距离,以目标已消耗的像素为单位

int dyConsumed

Vertical scroll distance in pixels already consumed by target
目标已消耗的垂直滚动距离(以像素为单位

int dxUnconsumed

Horizontal scroll distance in pixels not consumed by target
目标未占用的水平滚动距离(以像素为单位

int dyUnconsumed

Vertical scroll distance in pixels not consumed by target
目标未占用的垂直滚动距离(以像素为单位

int type

the type of input which cause this scroll event
引起滚动事件的输入类型

Added in 1.1.0 已在 1.1.0 中添加
abstract void onNestedScrollAccepted(
    @NonNull View child,
    @NonNull View target,
    int axes,
    int type
)

React to the successful claiming of a nested scroll operation.
对成功执行嵌套滚动操作做出反应。

This method will be called after onStartNestedScroll returns true. It offers an opportunity for the view and its superclasses to perform initial configuration for the nested scroll. Implementations of this method should always call their superclass's implementation of this method if one is present.
该方法将在 onStartNestedScroll 返回 true 后调用。它为视图及其超类提供了一个为嵌套滚动执行初始配置的机会。如果存在本方法的实现,则本方法的实现应始终调用其超类的实现。

Parameters 参数
@NonNull View child

Direct child of this ViewParent containing target
该 ViewParent 的直接子代,包含目标

@NonNull View target

View that initiated the nested scroll
启动嵌套滚动的视图

int axes

Flags consisting of SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_VERTICAL or both
SCROLL_AXIS_HORIZONTALSCROLL_AXIS_VERTICAL 或两者组成的标志

int type

the type of input which cause this scroll event
引起滚动事件的输入类型

Added in 1.1.0 已在 1.1.0 中添加
abstract boolean onStartNestedScroll(
    @NonNull View child,
    @NonNull View target,
    int axes,
    int type
)

React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate.
对启动可嵌套滚动操作的后代视图做出反应,并在适当情况下执行嵌套滚动操作。

This method will be called in response to a descendant view invoking startNestedScroll. Each parent up the view hierarchy will be given an opportunity to respond and claim the nested scrolling operation by returning true.
当子级视图调用 startNestedScroll 时,该方法将被调用。视图层次结构中的每个父级视图都将有机会做出响应,并通过返回 true 来执行嵌套滚动操作。

This method may be overridden by ViewParent implementations to indicate when the view is willing to support a nested scrolling operation that is about to begin. If it returns true, this ViewParent will become the target view's nested scrolling parent for the duration of the scroll operation in progress. When the nested scroll is finished this ViewParent will receive a call to onStopNestedScroll.
ViewParent 实现可以重载此方法,以指示视图何时愿意支持即将开始的嵌套滚动操作。如果该方法返回 true,那么在滚动操作进行期间,该 ViewParent 将成为目标视图的嵌套滚动父视图。当嵌套滚动结束时,该 ViewParent 将收到对 onStopNestedScroll 的调用。

Parameters 参数
@NonNull View child

Direct child of this ViewParent containing target
该 ViewParent 的直接子代,包含目标

@NonNull View target

View that initiated the nested scroll
启动嵌套滚动的视图

int axes

Flags consisting of SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_VERTICAL or both
SCROLL_AXIS_HORIZONTALSCROLL_AXIS_VERTICAL 或两者组成的标志

int type

the type of input which cause this scroll event
引起滚动事件的输入类型

Returns 返回
boolean

true if this ViewParent accepts the nested scroll operation
如果此 ViewParent 接受嵌套滚动操作,则为 true

Added in 1.1.0 已在 1.1.0 中添加
abstract void onStopNestedScroll(@NonNull View target, int type)

React to a nested scroll operation ending.
对嵌套滚动操作结束做出反应。

Perform cleanup after a nested scrolling operation. This method will be called when a nested scroll stops, for example when a nested touch scroll ends with a ACTION_UP or ACTION_CANCEL event. Implementations of this method should always call their superclass's implementation of this method if one is present.
执行嵌套滚动操作后的清理。当嵌套滚动停止时,例如当嵌套触摸滚动以 ACTION_UPACTION_CANCEL 事件结束时,该方法将被调用。如果存在超类,该方法的实现应始终调用超类的实现。

Parameters 参数
@NonNull View target

View that initiated the nested scroll
启动嵌套滚动的视图

int type

the type of input which cause this scroll event
引起滚动事件的输入类型

Discover the latest app development tools, platform updates, training, and documentation for developers across every Android device.

更新于 2023年8月12日

Android Studio 2022.2.1 Closed Issues

更新于 2023年5月25日

Discover the latest app development tools, platform updates, training, and documentation for developers across every Android device.

更新于 2024年2月17日