Added in API level 1

TouchDelegate


open class TouchDelegate
kotlin.Any
   ↳ android.view.TouchDelegate

Helper class to handle situations where you want a view to have a larger touch area than its actual view bounds. The view whose touch area is changed is called the delegate view. This class should be used by an ancestor of the delegate. To use a TouchDelegate, first create an instance that specifies the bounds that should be mapped to the delegate and the delegate view itself.

The ancestor should then forward all of its touch events received in its android.view.View#onTouchEvent(MotionEvent) to onTouchEvent(android.view.MotionEvent).

Summary

Constants
static Int

The touchable region of the View extends above its actual extent.

static Int

The touchable region of the View extends below its actual extent.

static Int

The touchable region of the View extends to the left of its actual extent.

static Int

The touchable region of the View extends to the right of its actual extent.

Public constructors
TouchDelegate(bounds: Rect!, delegateView: View!)

Constructor

Public methods
open AccessibilityNodeInfo.TouchDelegateInfo

Return a TouchDelegateInfo mapping from regions (in view coordinates) to delegated views for accessibility usage.

open Boolean

Forward touch events to the delegate view if the event is within the bounds specified in the constructor.

open Boolean

Forward hover events to the delegate view if the event is within the bounds specified in the constructor and touch exploration is enabled.

Constants

ABOVE

Added in API level 1
static val ABOVE: Int

The touchable region of the View extends above its actual extent.

Value: 1

BELOW

Added in API level 1
static val BELOW: Int

The touchable region of the View extends below its actual extent.

Value: 2

TO_LEFT

Added in API level 1
static val TO_LEFT: Int

The touchable region of the View extends to the left of its actual extent.

Value: 4

TO_RIGHT

Added in API level 1
static val TO_RIGHT: Int

The touchable region of the View extends to the right of its actual extent.

Value: 8

Public constructors

TouchDelegate

Added in API level 1
TouchDelegate(
    bounds: Rect!,
    delegateView: View!)

Constructor

Parameters
bounds Rect!: Bounds in local coordinates of the containing view that should be mapped to the delegate view
delegateView View!: The view that should receive motion events

Public methods

getTouchDelegateInfo

Added in API level 29
open fun getTouchDelegateInfo(): AccessibilityNodeInfo.TouchDelegateInfo

Return a TouchDelegateInfo mapping from regions (in view coordinates) to delegated views for accessibility usage.

Return
AccessibilityNodeInfo.TouchDelegateInfo A TouchDelegateInfo. This value cannot be null.

onTouchEvent

Added in API level 1
open fun onTouchEvent(event: MotionEvent): Boolean

Forward touch events to the delegate view if the event is within the bounds specified in the constructor.

Parameters
event MotionEvent: The touch event to forward This value cannot be null.
Return
Boolean True if the event was consumed by the delegate, false otherwise.

onTouchExplorationHoverEvent

Added in API level 29
open fun onTouchExplorationHoverEvent(event: MotionEvent): Boolean

Forward hover events to the delegate view if the event is within the bounds specified in the constructor and touch exploration is enabled.

This method is provided for accessibility purposes so touch exploration, which is commonly used by screen readers, can properly place accessibility focus on views that use touch delegates. Therefore, touch exploration must be enabled for hover events to be dispatched through the delegate.

Parameters
event MotionEvent: The hover event to forward This value cannot be null.
Return
Boolean True if the event was consumed by the delegate, false otherwise.