Google is committed to advancing racial equity for Black communities. See how.

NestedScrollingParent2

interface NestedScrollingParent2 : NestedScrollingParent
androidx.core.view.NestedScrollingParent2

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

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.

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.

Summary

Public methods
abstract Unit
onNestedPreScroll(@NonNull target: View, dx: Int, dy: Int, @NonNull consumed: IntArray, type: Int)

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

abstract Unit
onNestedScroll(@NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int)

React to a nested scroll in progress.

abstract Unit
onNestedScrollAccepted(@NonNull child: View, @NonNull target: View, axes: Int, type: Int)

React to the successful claiming of a nested scroll operation.

abstract Boolean
onStartNestedScroll(@NonNull child: View, @NonNull target: View, axes: Int, type: Int)

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

abstract Unit
onStopNestedScroll(@NonNull target: View, type: Int)

React to a nested scroll operation ending.

Inherited functions

Public methods

onNestedPreScroll

abstract fun onNestedPreScroll(
    @NonNull target: View,
    dx: Int,
    dy: Int,
    @NonNull consumed: IntArray,
    type: Int
): Unit

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 View#dispatchNestedPreScroll(int, int, int[], int[]). 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.

Parameters
target View: View that initiated the nested scroll
dx Int: Horizontal scroll distance in pixels
dy Int: Vertical scroll distance in pi