Android 12 Developer Preview is here! Try it out, and give us your feedback!

Callback

abstract class Callback
kotlin.Any
   ↳ androidx.customview.widget.ViewDragHelper.Callback

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

A Callback is used as a communication channel with the ViewDragHelper back to the parent view using it.

Public methods
open Int
clampViewPositionHorizontal(@NonNull child: View, left: Int, dx: Int)

Restrict the motion of the dragged child view along the horizontal axis.

open Int
clampViewPositionVertical(@NonNull child: View, top: Int, dy: Int)

Restrict the motion of the dragged child view along the vertical axis.

open Int

Called to determine the Z-order of child views.

open Int

Return the magnitude of a draggable child view's horizontal range of motion in pixels.

open Int
getViewVerticalDragRange(@NonNull child: View)

Return the magnitude of a draggable child view's vertical range of motion in pixels.

open Unit
onEdgeDragStarted(edgeFlags: Int, pointerId: Int)

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.

open Boolean
onEdgeLock(edgeFlags: Int)

Called when the given edge may become locked.

open Unit
onEdgeTouched(edgeFlags: Int, pointerId: Int)

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

open Unit
onViewCaptured(@NonNull capturedChild: View, activePointerId: Int)

Called when a child view is captured for dragging or settling.

open Unit

Called when the drag state changes.

open Unit
onViewPositionChanged(@NonNull changedView: View, left: Int, top: Int, @Px dx: Int, @Px dy: Int)

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

open Unit
onViewReleased(@NonNull releasedChild: View, xvel: Float, yvel: Float)

Called when the child view is no longer being actively dragged.

abstract Boolean
tryCaptureView(@NonNull child: View, pointerId: Int)

Called when the user's input indicates that they want to capture the given child view with the pointer indicated by pointerId.

Public constructors

<init>

Callback()

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.

Public methods

clampViewPositionHorizontal

open fun clampViewPositionHorizontal(
    @NonNull 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: Child view being dragged
left Int: Attempted motion along the X axis
dx Int: Proposed change in position for left
Return
Int The new clamped position for left

clampViewPositionVertical

open fun clampViewPositionVertical(
    @NonNull 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: Child view being dragged
top