# NestedScrollingParent

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/view/NestedScrollingParent.java+class:androidx.core.view.NestedScrollingParent) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***


```
public interface NestedScrollingParent
```

<br />

Known direct subclasses [NestedScrollingParent2](https://developer.android.com/reference/androidx/core/view/NestedScrollingParent2), [SwipeRefreshLayout](https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout), [WearableDrawerLayout](https://developer.android.com/reference/androidx/wear/widget/drawer/WearableDrawerLayout)

|---|---|
| `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent2` | This interface should be implemented by `https://developer.android.com/reference/android/view/ViewGroup.html` subclasses that wish to support scrolling operations delegated by a nested child view. |
| `https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout` | The SwipeRefreshLayout should be used whenever the user can refresh the contents of a view via a vertical swipe gesture. |
| `https://developer.android.com/reference/androidx/wear/widget/drawer/WearableDrawerLayout` | Top-level container that allows interactive drawers to be pulled from the top and bottom edge of the window. |

Known indirect subclasses [CoordinatorLayout](https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout), [MotionLayout](https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionLayout), [NestedScrollView](https://developer.android.com/reference/androidx/core/widget/NestedScrollView), [NestedScrollingParent3](https://developer.android.com/reference/androidx/core/view/NestedScrollingParent3), [SwipeRefreshLayout](https://developer.android.com/reference/androidx/swiperefreshlayout/widget/SwipeRefreshLayout)

|---|---|
| `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout` | CoordinatorLayout is a super-powered `https://developer.android.com/reference/android/widget/FrameLayout.html`. |
| `https://developer.android.com/reference/androidx/constraintlayout/motion/widget/MotionLayout` | A subclass of ConstraintLayout that supports animating between various states **Added in 2.0** |
| `https://developer.android.com/reference/androidx/core/widget/NestedScrollView` | NestedScrollView is just like `https://developer.android.com/reference/android/widget/ScrollView.html`, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. |
| `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent3` | This interface should be implemented by `https://developer.android.com/reference/android/view/ViewGroup.html` subclasses that wish to support scrolling operations delegated by a nested child view. |
| `https://developer.android.com/reference/androidx/swiperefreshlayout/widget/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 `https://developer.android.com/reference/android/view/ViewGroup.html` subclasses that wish to support scrolling operations delegated by a nested child view.

Classes implementing this interface should create a final instance of a `https://developer.android.com/reference/androidx/core/view/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 `https://developer.android.com/reference/androidx/core/view/ViewCompat`, `https://developer.android.com/reference/androidx/core/view/ViewGroupCompat` or `https://developer.android.com/reference/androidx/core/view/ViewParentCompat` compatibility shim static methods. This ensures interoperability with nested scrolling views on Android 5.0 Lollipop and newer.

## Summary

| ### Public methods |
|---|---|
| `abstract int` | `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#getNestedScrollAxes()()` Return the current axes of nested scrolling for this NestedScrollingParent. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#onNestedFling(android.view.View,float,float,boolean)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html target, float velocityX, float velocityY, boolean consumed )` Request a fling from a nested scroll. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#onNestedPreFling(android.view.View,float,float)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html target, float velocityX, float velocityY)` React to a nested fling before the target view consumes it. |
| `abstract void` | `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#onNestedPreScroll(android.view.View,int,int,int[])( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html target, int dx, int dy, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html int[] consumed )` React to a nested scroll in progress before the target view consumes a portion of the scroll. |
| `abstract void` | `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#onNestedScroll(android.view.View,int,int,int,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed )` React to a nested scroll in progress. |
| `abstract void` | `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#onNestedScrollAccepted(android.view.View,android.view.View,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html child, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html target, int axes)` React to the successful claiming of a nested scroll operation. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#onStartNestedScroll(android.view.View,android.view.View,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html child, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html target, int axes)` React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate. |
| `abstract void` | `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#onStopNestedScroll(android.view.View)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html target)` React to a nested scroll operation ending. |

## Public methods

### getNestedScrollAxes

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
abstract int getNestedScrollAxes()
```

Return the current axes of nested scrolling for this NestedScrollingParent.

A NestedScrollingParent returning something other than `https://developer.android.com/reference/androidx/core/view/ViewCompat#SCROLL_AXIS_NONE()` is currently acting as a nested scrolling parent for one or more descendant views in the hierarchy.

| Returns |
|---|---|
| `int` | Flags indicating the current axes of nested scrolling |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/ViewCompat#SCROLL_AXIS_HORIZONTAL()` |   |
| `https://developer.android.com/reference/androidx/core/view/ViewCompat#SCROLL_AXIS_VERTICAL()` |   |
| `https://developer.android.com/reference/androidx/core/view/ViewCompat#SCROLL_AXIS_NONE()` |   |

### onNestedFling

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

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

Request a fling from a nested scroll.

This method signifies that a nested scrolling child has detected suitable conditions for a fling. Generally this means that a touch scroll has ended with a `https://developer.android.com/reference/android/view/VelocityTracker.html` in the direction of scrolling that meets or exceeds the `https://developer.android.com/reference/android/view/ViewConfiguration.html#getScaledMinimumFlingVelocity()` along a scrollable axis.

If a nested scrolling child view would normally fling but it is at the edge of its own content, it can use this method to delegate the fling to its nested scrolling parent instead. The parent may optionally consume the fling or observe a child fling.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html target` | View that initiated the nested scroll |
| `float velocityX` | Horizontal velocity in pixels per second |
| `float velocityY` | Vertical velocity in pixels per second |
| `boolean consumed` | true if the child consumed the fling, false otherwise |

| Returns |
|---|---|
| `boolean` | true if this parent consumed or otherwise reacted to the fling |

### onNestedPreFling

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

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

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

This method siginfies that a nested scrolling child has detected a fling with the given velocity along each axis. Generally this means that a touch scroll has ended with a `https://developer.android.com/reference/android/view/VelocityTracker.html` in the direction of scrolling that meets or exceeds the `https://developer.android.com/reference/android/view/ViewConfiguration.html#getScaledMinimumFlingVelocity()` along a scrollable axis.

If a nested scrolling parent is consuming motion as part of a `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#onNestedPreScroll(android.view.View,int,int,int[])`, 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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html target` | View that initiated the nested scroll |
| `float velocityX` | Horizontal velocity in pixels per second |
| `float velocityY` | Vertical velocity in pixels per second |

| Returns |
|---|---|
| `boolean` | true if this parent consumed the fling ahead of the target view |

### onNestedPreScroll

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
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.

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 `https://developer.android.com/reference/android/view/View.html#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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html target` | View that initiated the nested scroll |
| `int dx` | Horizontal scroll distance in pixels |
| `int dy` | Vertical scroll distance in pixels |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html int[] consumed` | Output. The horizontal and vertical scroll distance consumed by this parent |

### onNestedScroll

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

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

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 `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#onStartNestedScroll(android.view.View,android.view.View,int)`.

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.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html 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 |

### onNestedScrollAccepted

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

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

React to the successful claiming of a nested scroll operation.

This method will be called after `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#onStartNestedScroll(android.view.View,android.view.View,int)` 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.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html child` | Direct child of this ViewParent containing target |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html target` | View that initiated the nested scroll |
| `int axes` | Flags consisting of `https://developer.android.com/reference/androidx/core/view/ViewCompat#SCROLL_AXIS_HORIZONTAL()`, `https://developer.android.com/reference/androidx/core/view/ViewCompat#SCROLL_AXIS_VERTICAL()` or both |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#onStartNestedScroll(android.view.View,android.view.View,int)` |   |
| `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#onStopNestedScroll(android.view.View)` |   |

### onStartNestedScroll

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
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.

This method will be called in response to a descendant view invoking `https://developer.android.com/reference/androidx/core/view/ViewCompat#startNestedScroll(android.view.View,int)`. Each parent up the view hierarchy will be given an opportunity to respond and claim the nested scrolling operation by returning `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 `https://developer.android.com/reference/androidx/core/view/NestedScrollingParent#onStopNestedScroll(android.view.View)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html child` | Direct child of this ViewParent containing target |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html target` | View that initiated the nested scroll |
| `int axes` | Flags consisting of `https://developer.android.com/reference/androidx/core/view/ViewCompat#SCROLL_AXIS_HORIZONTAL()`, `https://developer.android.com/reference/androidx/core/view/ViewCompat#SCROLL_AXIS_VERTICAL()` or both |

| Returns |
|---|---|
| `boolean` | true if this ViewParent accepts the nested scroll operation |

### onStopNestedScroll

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
abstract void onStopNestedScroll(@NonNull View target)
```

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 `https://developer.android.com/reference/android/view/MotionEvent.html#ACTION_UP` or `https://developer.android.com/reference/android/view/MotionEvent.html#ACTION_CANCEL` event. Implementations of this method should always call their superclass's implementation of this method if one is present.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/View.html target` | View that initiated the nested scroll |