# NestedScrollingChild2

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

*** ** * ** ***

<br />

```
interface NestedScrollingChild2 : NestedScrollingChild
```

<br />

Known direct subclasses [NestedScrollingChild3](https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild3), [RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView), [SwipeRefreshLayout](https://developer.android.com/reference/kotlin/androidx/swiperefreshlayout/widget/SwipeRefreshLayout)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild3` | This interface should be implemented by `https://developer.android.com/reference/android/view/View.html` subclasses that wish to support dispatching nested scrolling operations to a cooperating parent `https://developer.android.com/reference/android/view/ViewGroup.html`. |
| `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView` | A flexible view for providing a limited window into a large data set. |
| `https://developer.android.com/reference/kotlin/androidx/swiperefreshlayout/widget/SwipeRefreshLayout` | The SwipeRefreshLayout should be used whenever the user can refresh the contents of a view via a vertical swipe gesture. |

Known indirect subclasses [BaseGridView](https://developer.android.com/reference/kotlin/androidx/leanback/widget/BaseGridView), [HorizontalGridView](https://developer.android.com/reference/kotlin/androidx/leanback/widget/HorizontalGridView), [NestedScrollView](https://developer.android.com/reference/kotlin/androidx/core/widget/NestedScrollView), [RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView), [SwipeRefreshLayout](https://developer.android.com/reference/kotlin/androidx/swiperefreshlayout/widget/SwipeRefreshLayout), [VerticalGridView](https://developer.android.com/reference/kotlin/androidx/leanback/widget/VerticalGridView), [WearableRecyclerView](https://developer.android.com/reference/kotlin/androidx/wear/widget/WearableRecyclerView)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/leanback/widget/BaseGridView` | An abstract base class for vertically and horizontally scrolling lists. |
| `https://developer.android.com/reference/kotlin/androidx/leanback/widget/HorizontalGridView` | A `https://developer.android.com/reference/android/view/ViewGroup.html` that shows items in a horizontal scrolling list. |
| `https://developer.android.com/reference/kotlin/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/kotlin/androidx/recyclerview/widget/RecyclerView` | A flexible view for providing a limited window into a large data set. |
| `https://developer.android.com/reference/kotlin/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/kotlin/androidx/leanback/widget/VerticalGridView` | A `https://developer.android.com/reference/android/view/ViewGroup.html` that shows items in a vertically scrolling list. |
| `https://developer.android.com/reference/kotlin/androidx/wear/widget/WearableRecyclerView` | Wearable specific implementation of the `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView` enabling `https://developer.android.com/reference/kotlin/androidx/wear/widget/WearableRecyclerView#setCircularScrollingGestureEnabled(boolean)` circular scrolling} and semi-circular layouts. |

*** ** * ** ***

This interface should be implemented by `https://developer.android.com/reference/android/view/View.html` subclasses that wish to support dispatching nested scrolling operations to a cooperating parent `https://developer.android.com/reference/android/view/ViewGroup.html`.

Classes implementing this interface should create a final instance of a `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChildHelper` as a field and delegate any View methods to the `NestedScrollingChildHelper` methods of the same signature.

Views invoking nested scrolling functionality should always do so from the relevant `https://developer.android.com/reference/kotlin/androidx/core/view/ViewCompat`, `https://developer.android.com/reference/kotlin/androidx/core/view/ViewGroupCompat` or `https://developer.android.com/reference/kotlin/androidx/core/view/ViewParentCompat` compatibility shim static methods. This ensures interoperability with nested scrolling views on all versions of Android.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#dispatchNestedPreScroll(int,int,int[],int[],int)( dx: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, dy: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, consumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>?, offsetInWindow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>?, type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Dispatch one step of a nested scroll in progress before this view consumes any portion of it. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#dispatchNestedScroll(int,int,int,int,int[],int)( dxConsumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, dyConsumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, dxUnconsumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, dyUnconsumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, offsetInWindow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>?, type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Dispatch one step of a nested scroll in progress. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#hasNestedScrollingParent(int)(type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns true if this view has a nested scrolling parent for the given input type. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#startNestedScroll(int,int)(axes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Begin a nestable scroll operation along the given axes, for the given input type. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#stopNestedScroll(int)(type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Stop a nested scroll in progress for the given input type. |

### Inherited functions

From [androidx.core.view.NestedScrollingChild](https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild#dispatchNestedFling(float,float,boolean)(velocityX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, velocityY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, consumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`

Dispatch a fling to a nested scrolling parent.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild#dispatchNestedPreFling(float,float)(velocityX: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, velocityY: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`

Dispatch a fling to a nested scrolling parent before it is processed by this view.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild#dispatchNestedPreScroll(int,int,int[],int[])(

dx: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,

dy: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,

consumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>?,

offsetInWindow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>?

)`

Dispatch one step of a nested scroll in progress before this view consumes any portion of it.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild#dispatchNestedScroll(int,int,int,int,int[])(

dxConsumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,

dyConsumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,

dxUnconsumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,

dyUnconsumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,

offsetInWindow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>?

)`

Dispatch one step of a nested scroll in progress.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild#hasNestedScrollingParent()()`

Returns true if this view has a nested scrolling parent.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild#isNestedScrollingEnabled()()`

Returns true if nested scrolling is enabled for this view.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild#setNestedScrollingEnabled(boolean)(enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`

Enable or disable nested scrolling for this view.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild#startNestedScroll(int)(axes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

Begin a nestable scroll operation along the given axes.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild#stopNestedScroll()()`

Stop a nested scroll in progress.

## Public functions

### dispatchNestedPreScroll

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

```
fun dispatchNestedPreScroll(
    dx: Int,
    dy: Int,
    consumed: IntArray<Int>?,
    offsetInWindow: IntArray<Int>?,
    type: Int
): Boolean
```

Dispatch one step of a nested scroll in progress before this view consumes any portion of it.

Nested pre-scroll events are to nested scroll events what touch intercept is to touch. `dispatchNestedPreScroll` offers an opportunity for the parent view in a nested scrolling operation to consume some or all of the scroll operation before the child view consumes it.

| Parameters |
|---|---|
| `dx: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Horizontal scroll distance in pixels |
| `dy: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Vertical scroll distance in pixels |
| `consumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>?` | Output. If not null, consumed\[0\] will contain the consumed component of dx and consumed\[1\] the consumed dy. |
| `offsetInWindow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>?` | Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking. |
| `type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the type of input which cause this scroll event |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the parent consumed some or all of the scroll delta |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#dispatchNestedScroll(int,int,int,int,int[],int)` |   |

### dispatchNestedScroll

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

```
fun dispatchNestedScroll(
    dxConsumed: Int,
    dyConsumed: Int,
    dxUnconsumed: Int,
    dyUnconsumed: Int,
    offsetInWindow: IntArray<Int>?,
    type: Int
): Boolean
```

Dispatch one step of a nested scroll in progress.

Implementations of views that support nested scrolling should call this to report info about a scroll in progress to the current nested scrolling parent. If a nested scroll is not currently in progress or nested scrolling is not `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild#isNestedScrollingEnabled()` for this view this method does nothing.

Compatible View implementations should also call `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#dispatchNestedPreScroll(int,int,int[],int[],int)` before consuming a component of the scroll event themselves.

| Parameters |
|---|---|
| `dxConsumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Horizontal distance in pixels consumed by this view during this scroll step |
| `dyConsumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Vertical distance in pixels consumed by this view during this scroll step |
| `dxUnconsumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Horizontal scroll distance in pixels not consumed by this view |
| `dyUnconsumed: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Horizontal scroll distance in pixels not consumed by this view |
| `offsetInWindow: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>?` | Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking. |
| `type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the type of input which cause this scroll event |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if the event was dispatched, false if it could not be dispatched. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#dispatchNestedPreScroll(int,int,int[],int[],int)` |   |

### hasNestedScrollingParent

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

```
fun hasNestedScrollingParent(type: Int): Boolean
```

Returns true if this view has a nested scrolling parent for the given input type.

The presence of a nested scrolling parent indicates that this view has initiated a nested scroll and it was accepted by an ancestor view further up the view hierarchy.

| Parameters |
|---|---|
| `type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the type of input which cause this scroll event |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | whether this view has a nested scrolling parent |

### startNestedScroll

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

```
fun startNestedScroll(axes: Int, type: Int): Boolean
```

Begin a nestable scroll operation along the given axes, for the given input type.

A view starting a nested scroll promises to abide by the following contract:

The view will call startNestedScroll upon initiating a scroll operation. In the case of a touch scroll type this corresponds to the initial `https://developer.android.com/reference/android/view/MotionEvent.html#ACTION_DOWN`. In the case of touch scrolling the nested scroll will be terminated automatically in the same manner as `https://developer.android.com/reference/android/view/ViewParent.html#requestDisallowInterceptTouchEvent(boolean)`. In the event of programmatic scrolling the caller must explicitly call `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#stopNestedScroll(int)` to indicate the end of the nested scroll.

If `startNestedScroll` returns true, a cooperative parent was found. If it returns false the caller may ignore the rest of this contract until the next scroll. Calling startNestedScroll while a nested scroll is already in progress will return true.

At each incremental step of the scroll the caller should invoke `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#dispatchNestedPreScroll(int,int,int[],int[],int)` once it has calculated the requested scrolling delta. If it returns true the nested scrolling parent at least partially consumed the scroll and the caller should adjust the amount it scrolls by.

After applying the remainder of the scroll delta the caller should invoke `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#dispatchNestedScroll(int,int,int,int,int[],int)`, passing both the delta consumed and the delta unconsumed. A nested scrolling parent may treat these values differently. See `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingParent2#onNestedScroll(android.view.View,int,int,int,int,int)`.

| Parameters |
|---|---|
| `axes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Flags consisting of a combination of `https://developer.android.com/reference/kotlin/androidx/core/view/ViewCompat#SCROLL_AXIS_HORIZONTAL()` and/or `https://developer.android.com/reference/kotlin/androidx/core/view/ViewCompat#SCROLL_AXIS_VERTICAL()`. |
| `type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the type of input which cause this scroll event |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if a cooperative parent was found and nested scrolling has been enabled for the current gesture. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#stopNestedScroll(int)` |   |
| `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#dispatchNestedPreScroll(int,int,int[],int[],int)` |   |
| `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#dispatchNestedScroll(int,int,int,int,int[],int)` |   |

### stopNestedScroll

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

```
fun stopNestedScroll(type: Int): Unit
```

Stop a nested scroll in progress for the given input type.

Calling this method when a nested scroll is not currently in progress is harmless.

| Parameters |
|---|---|
| `type: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the type of input which cause this scroll event |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/view/NestedScrollingChild2#startNestedScroll(int,int)` |   |