鸿蒙OS开发文档 鸿蒙OS Component.DraggedListener

2024-02-25 开发教程 鸿蒙OS开发文档 匿名 1

Component.DraggedListener

public static interface Component.DraggedListener

提供当手势识别器将拖动事件分派到组件时要调用的回调。

方法总结

修饰符和类型方法描述
voidonDragCancel(Component component, DragInfo dragInfo)处理分派给组件的拖动取消事件。
voidonDragDown(Component component, DragInfo dragInfo)处理分派给组件的下拉事件。
voidonDragEnd(Component component, DragInfo dragInfo)处理分派给组件的拖动结束事件。
default booleanonDragPreAccept(Component component, int dragDirection)接受分派给组件的拖动事件。
voidonDragStart(Component component, DragInfo dragInfo)处理分派给组件的拖动开始事件。
voidonDragUpdate(Component component, DragInfo dragInfo)处理分派给组件的拖动更新事件。

方法详情

onDragDown

void onDragDown(Component component, DragInfo dragInfo)

处理分派给组件的下拉事件。

参数:

参数名称参数描述
component指示拖拽事件被调度到的组件。
dragInfo指示下拉信息对象 DragInfo。

onDragStart

void onDragStart(Component component, DragInfo dragInfo)

处理分派给组件的拖动开始事件。

参数:

参数名称参数描述
component指示拖动开始事件被调度到的组件。
dragInfo指示拖动开始信息对象 DragInfo。

onDragUpdate

void onDragUpdate(Component component, DragInfo dragInfo)

处理分派给组件的拖动更新事件。

参数:

参数名称参数描述
component指示拖动更新事件被调度到的组件。
dragInfo指示拖动更新信息对象 DragInfo。

onDragEnd

void onDragEnd(Component component, DragInfo dragInfo)

处理分派给组件的拖动结束事件。

参数:

参数名称参数描述
component指示拖拽结束事件被调度到的组件。
dragInfo表示拖动结束信息对象 DragInfo。

onDragCancel

void onDragCancel(Component component, DragInfo dragInfo)

处理分派给组件的拖动取消事件。

参数:

参数名称参数描述
component指示拖拽结束事件被调度到的组件。
dragInfo表示拖动结束信息对象 DragInfo。

onDragPreAccept

default boolean onDragPreAccept(Component component, int dragDirection)

接受分派给组件的拖动事件。

此方法支持 Component.DRAG_HORIZONTAL、Component.DRAG_VERTICAL 和 Component.DRAG_HORIZONTAL_VERTICAL。 当设置了 Component.DRAG_HORIZONTAL_VERTICAL 时,拖动方向可能会比较粗略。

参数:

参数名称参数描述
component指示拖动事件被调度到的组件。
dragDirection指示拖动方向,可以是 Component.DRAG_UP、Component.DRAG_DOWN、Component.DRAG_LEFT 或 Component.DRAG_RIGHT。

返回:

如果当前拖动事件被接受,则返回 true(默认值); 否则返回 false。