# ViewDragHelper.Callback

# ViewDragHelper.Callback

Artifact:[androidx.customview:customview](https://developer.android.com/jetpack/androidx/releases/customview)  
[View Source](https://cs.android.com/search?q=file:androidx/customview/widget/ViewDragHelper.java+class:androidx.customview.widget.ViewDragHelper.Callback)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/customview#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/customview/widget/ViewDragHelper.Callback "View this page in Java")

<br />

```
abstract class ViewDragHelper.Callback
```

<br />

*** ** * ** ***

A Callback is used as a communication channel with the ViewDragHelper back to the parent view using it.`on*`methods are invoked on siginficant events and several accessor methods are expected to provide the ViewDragHelper with more information about the state of the parent view upon request. The callback also makes decisions governing the range and draggability of child views.

## Summary

|                                                   ### Public constructors                                                    |
|------------------------------------------------------------------------------------------------------------------------------|
| [Callback](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#Callback())`()` |

|                                      ### Public functions                                      |
|------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                    | [clampViewPositionHorizontal](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#clampViewPositionHorizontal(android.view.View,int,int))`(child: `[View](https://developer.android.com/reference/android/view/View.html)`, left: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, dx: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Restrict the motion of the dragged child view along the horizontal axis.                                                                                                                                                                                                                                                                                                                                                                    |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                    | [clampViewPositionVertical](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#clampViewPositionVertical(android.view.View,int,int))`(child: `[View](https://developer.android.com/reference/android/view/View.html)`, top: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, dy: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Restrict the motion of the dragged child view along the vertical axis.                                                                                                                                                                                                                                                                                                                                                                           |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                    | [getOrderedChildIndex](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#getOrderedChildIndex(int))`(index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Called to determine the Z-order of child views.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                    | [getViewHorizontalDragRange](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#getViewHorizontalDragRange(android.view.View))`(child: `[View](https://developer.android.com/reference/android/view/View.html)`)` Return the magnitude of a draggable child view's horizontal range of motion in pixels.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                    | [getViewVerticalDragRange](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#getViewVerticalDragRange(android.view.View))`(child: `[View](https://developer.android.com/reference/android/view/View.html)`)` Return the magnitude of a draggable child view's vertical range of motion in pixels.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                  | [onEdgeDragStarted](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#onEdgeDragStarted(int,int))`(edgeFlags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, pointerId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Called when the user has started a deliberate drag away from one of the subscribed edges in the parent view while no child view is currently captured.                                                                                                                                                                                                                                                                                                                                                                                                 |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)            | [onEdgeLock](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#onEdgeLock(int))`(edgeFlags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Called when the given edge may become locked.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                  | [onEdgeTouched](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#onEdgeTouched(int,int))`(edgeFlags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, pointerId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Called when one of the subscribed edges in the parent view has been touched by the user while no child view is currently captured.                                                                                                                                                                                                                                                                                                                                                                                                                             |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                  | [onViewCaptured](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#onViewCaptured(android.view.View,int))`(capturedChild: `[View](https://developer.android.com/reference/android/view/View.html)`, activePointerId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Called when a child view is captured for dragging or settling.                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                  | [onViewDragStateChanged](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#onViewDragStateChanged(int))`(state: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Called when the drag state changes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                  | [onViewPositionChanged](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#onViewPositionChanged(android.view.View,int,int,int,int))`(` ` changedView: `[View](https://developer.android.com/reference/android/view/View.html)`,` ` left: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` top: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` dx: @`[Px](https://developer.android.com/reference/kotlin/androidx/annotation/Px)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` dy: @`[Px](https://developer.android.com/reference/kotlin/androidx/annotation/Px)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Called when the captured view's position changes as the result of a drag or settle. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                  | [onViewReleased](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#onViewReleased(android.view.View,float,float))`(releasedChild: `[View](https://developer.android.com/reference/android/view/View.html)`, xvel: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`, yvel: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Called when the child view is no longer being actively dragged.                                                                                                                                                                                                                                                                                                                                                                                 |
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [tryCaptureView](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#tryCaptureView(android.view.View,int))`(child: `[View](https://developer.android.com/reference/android/view/View.html)`, pointerId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Called when the user's input indicates that they want to capture the given child view with the pointer indicated by pointerId.                                                                                                                                                                                                                                                                                                                                                                                                                          |

## Public constructors

### Callback

Added in 1.0.0  

```
Callback()
```  

## Public functions

### clampViewPositionHorizontal

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

```
fun clampViewPositionHorizontal(child: View, left: Int, dx: Int): Int
```

Restrict the motion of the dragged child view along the horizontal axis. The default implementation does not allow horizontal motion; the extending class must override this method and provide the desired clamping.  

|                                     Parameters                                      |
|-------------------------------------------------------------------------------------|--------------------------------------|
| `child: `[View](https://developer.android.com/reference/android/view/View.html)     | Child view being dragged             |
| `left: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Attempted motion along the X axis    |
| `dx: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)   | Proposed change in position for left |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-----------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The new clamped position for left |

### clampViewPositionVertical

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

```
fun clampViewPositionVertical(child: View, top: Int, dy: Int): Int
```

Restrict the motion of the dragged child view along the vertical axis. The default implementation does not allow vertical motion; the extending class must override this method and provide the desired clamping.  

|                                     Parameters                                     |
|------------------------------------------------------------------------------------|-------------------------------------|
| `child: `[View](https://developer.android.com/reference/android/view/View.html)    | Child view being dragged            |
| `top: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Attempted motion along the Y axis   |
| `dy: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)  | Proposed change in position for top |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|----------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The new clamped position for top |

### getOrderedChildIndex

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

```
fun getOrderedChildIndex(index: Int): Int
```

Called to determine the Z-order of child views.  

|                                      Parameters                                      |
|--------------------------------------------------------------------------------------|-----------------------------------|
| `index: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | the ordered position to query for |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | index of the view that should be ordered at position`index` |

### getViewHorizontalDragRange

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

```
fun getViewHorizontalDragRange(child: View): Int
```

Return the magnitude of a draggable child view's horizontal range of motion in pixels. This method should return 0 for views that cannot move horizontally.  

|                                   Parameters                                    |
|---------------------------------------------------------------------------------|---------------------|
| `child: `[View](https://developer.android.com/reference/android/view/View.html) | Child view to check |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|--------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | range of horizontal motion in pixels |

### getViewVerticalDragRange

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

```
fun getViewVerticalDragRange(child: View): Int
```

Return the magnitude of a draggable child view's vertical range of motion in pixels. This method should return 0 for views that cannot move vertically.  

|                                   Parameters                                    |
|---------------------------------------------------------------------------------|---------------------|
| `child: `[View](https://developer.android.com/reference/android/view/View.html) | Child view to check |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | range of vertical motion in pixels |

### onEdgeDragStarted

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

```
fun onEdgeDragStarted(edgeFlags: Int, pointerId: Int): Unit
```

Called when the user has started a deliberate drag away from one of the subscribed edges in the parent view while no child view is currently captured.  

|                                        Parameters                                        |
|------------------------------------------------------------------------------------------|------------------------------------------------------------|
| `edgeFlags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | A combination of edge flags describing the edge(s) dragged |
| `pointerId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | ID of the pointer touching the described edge(s)           |

|                                                       See also                                                        |
|-----------------------------------------------------------------------------------------------------------------------|---|
| [EDGE_LEFT](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#EDGE_LEFT())     |   |
| [EDGE_TOP](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#EDGE_TOP())       |   |
| [EDGE_RIGHT](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#EDGE_RIGHT())   |   |
| [EDGE_BOTTOM](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#EDGE_BOTTOM()) |   |

### onEdgeLock

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

```
fun onEdgeLock(edgeFlags: Int): Boolean
```

Called when the given edge may become locked. This can happen if an edge drag was preliminarily rejected before beginning, but after[onEdgeTouched](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#onEdgeTouched(int,int))was called. This method should return true to lock this edge or false to leave it unlocked. The default behavior is to leave edges unlocked.  

|                                        Parameters                                        |
|------------------------------------------------------------------------------------------|-----------------------------------------------------------|
| `edgeFlags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | A combination of edge flags describing the edge(s) locked |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|---------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | true to lock the edge, false to leave it unlocked |

### onEdgeTouched

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

```
fun onEdgeTouched(edgeFlags: Int, pointerId: Int): Unit
```

Called when one of the subscribed edges in the parent view has been touched by the user while no child view is currently captured.  

|                                        Parameters                                        |
|------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| `edgeFlags: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | A combination of edge flags describing the edge(s) currently touched |
| `pointerId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | ID of the pointer touching the described edge(s)                     |

|                                                       See also                                                        |
|-----------------------------------------------------------------------------------------------------------------------|---|
| [EDGE_LEFT](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#EDGE_LEFT())     |   |
| [EDGE_TOP](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#EDGE_TOP())       |   |
| [EDGE_RIGHT](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#EDGE_RIGHT())   |   |
| [EDGE_BOTTOM](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#EDGE_BOTTOM()) |   |

### onViewCaptured

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

```
fun onViewCaptured(capturedChild: View, activePointerId: Int): Unit
```

Called when a child view is captured for dragging or settling. The ID of the pointer currently dragging the captured view is supplied. If activePointerId is identified as[INVALID_POINTER](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#INVALID_POINTER())the capture is programmatic instead of pointer-initiated.  

|                                           Parameters                                           |
|------------------------------------------------------------------------------------------------|---------------------------------------|
| `capturedChild: `[View](https://developer.android.com/reference/android/view/View.html)        | Child view that was captured          |
| `activePointerId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Pointer id tracking the child capture |

### onViewDragStateChanged

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

```
fun onViewDragStateChanged(state: Int): Unit
```

Called when the drag state changes. See the`STATE_*`constants for more information.  

|                                      Parameters                                      |
|--------------------------------------------------------------------------------------|--------------------|
| `state: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The new drag state |

|                                                          See also                                                           |
|-----------------------------------------------------------------------------------------------------------------------------|---|
| [STATE_IDLE](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#STATE_IDLE())         |   |
| [STATE_DRAGGING](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#STATE_DRAGGING()) |   |
| [STATE_SETTLING](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#STATE_SETTLING()) |   |

### onViewPositionChanged

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

```
fun onViewPositionChanged(
    changedView: View,
    left: Int,
    top: Int,
    dx: @Px Int,
    dy: @Px Int
): Unit
```

Called when the captured view's position changes as the result of a drag or settle.  

|                                                                            Parameters                                                                            |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| `changedView: `[View](https://developer.android.com/reference/android/view/View.html)                                                                            | View whose position changed                   |
| `left: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                              | New X coordinate of the left edge of the view |
| `top: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                               | New Y coordinate of the top edge of the view  |
| `dx: @`[Px](https://developer.android.com/reference/kotlin/androidx/annotation/Px)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Change in X position from the last call       |
| `dy: @`[Px](https://developer.android.com/reference/kotlin/androidx/annotation/Px)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Change in Y position from the last call       |

### onViewReleased

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

```
fun onViewReleased(releasedChild: View, xvel: Float, yvel: Float): Unit
```

Called when the child view is no longer being actively dragged. The fling velocity is also supplied, if relevant. The velocity values may be clamped to system minimums or maximums.

Calling code may decide to fling or otherwise release the view to let it settle into place. It should do so using[settleCapturedViewAt](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#settleCapturedViewAt(int,int))or[flingCapturedView](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#flingCapturedView(int,int,int,int)). If the Callback invokes one of these methods, the ViewDragHelper will enter[STATE_SETTLING](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#STATE_SETTLING())and the view capture will not fully end until it comes to a complete stop. If neither of these methods is invoked before`onViewReleased`returns, the view will stop in place and the ViewDragHelper will return to[STATE_IDLE](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper#STATE_IDLE()).  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
| `releasedChild: `[View](https://developer.android.com/reference/android/view/View.html) | The captured child view now being released                            |
| `xvel: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | X velocity of the pointer as it left the screen in pixels per second. |
| `yvel: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | Y velocity of the pointer as it left the screen in pixels per second. |

### tryCaptureView

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

```
abstract fun tryCaptureView(child: View, pointerId: Int): Boolean
```

Called when the user's input indicates that they want to capture the given child view with the pointer indicated by pointerId. The callback should return true if the user is permitted to drag the given view with the indicated pointer.

ViewDragHelper may call this method multiple times for the same view even if the view is already captured; this indicates that a new pointer is trying to take control of the view.

If this method returns true, a call to[onViewCaptured](https://developer.android.com/reference/kotlin/androidx/customview/widget/ViewDragHelper.Callback#onViewCaptured(android.view.View,int))will follow if the capture is successful.  

|                                        Parameters                                        |
|------------------------------------------------------------------------------------------|------------------------------------------|
| `child: `[View](https://developer.android.com/reference/android/view/View.html)          | Child the user is attempting to capture  |
| `pointerId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | ID of the pointer attempting the capture |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|----------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | true if capture should be allowed, false otherwise |