鸿蒙Harmony 拖动监听DraggedListener

鸿蒙Harmony 拖动监听DraggedListener

/**
 * @param dragMode 设置拦截拖拽方向 Component.DRAG_HORIZONTAL_VERTICAL
 *     public static final int DRAG_DOWN = 2;
 *     public static final int DRAG_HORIZONTAL = 2;
 *     public static final int DRAG_HORIZONTAL_VERTICAL = 1;
 *     public static final int DRAG_LEFT = 3;
 *     public static final int DRAG_RIGHT = 4;
 *     public static final int DRAG_UP = 1;
 *     public static final int DRAG_VERTICAL = 3;
 * @param listener DraggedListener 拖动监听
 */
public void setDraggedListener(int dragMode, Component.DraggedListener listener)
public interface DraggedListener {
    void onDragDown(Component var1, DragInfo var2);
    void onDragStart(Component var1, DragInfo var2);
    void onDragUpdate(Component var1, DragInfo var2);
    void onDragEnd(Component var1, DragInfo var2);
    void onDragCancel(Component var1, DragInfo var2);
    // 返回值 true 拦截滑动事件
    default boolean onDragPreAccept(Component component, int dragDirection) { throw new RuntimeException("Stub!"); }
}
public class DragInfo {
    public final Point downPoint = null;
    public final Point startPoint = null;
    public final Point updatePoint = null;
    public final double xOffset = 0.0D;
    // x轴方向速度,测试发现目前返回值全部为0
    public final double xVelocity = 0.0D;
    public final double yOffset = 0.0D;
    public final double yVelocity = 0.0D;

    public DragInfo(Point downPoint, Point startPoint, Point updatePoint, double xOffset, double yOffset, double xVelocity, double yVelocity) {
        throw new RuntimeException("Stub!");
    }
}

点击事件

onDragDown
onDragCancel

滑动事件

true
flase
onDragDown
onDragPreAccept
onDragStart
onDragUpdate
onDragEnd
onDragCancel

层级事件最上层向下层传递
在这里插入图片描述

  • 点击事件
01-31 20:48:05.851 16868-16868/com.example.harmonyapp E 00001/app: B onDragDown
01-31 20:48:05.851 16868-16868/com.example.harmonyapp E 00001/app: A onDragDown
01-31 20:48:05.888 16868-16868/com.example.harmonyapp E 00001/app: B onDragCancel
01-31 20:48:05.888 16868-16868/com.example.harmonyapp E 00001/app: A onDragCancel

上层拦截点击事件

component.setClickable(true);
  • 滑动事件
    A拦截消费
01-31 20:50:03.966 16868-16868/com.example.harmonyapp E 00001/app: B onDragDown
01-31 20:50:03.966 16868-16868/com.example.harmonyapp E 00001/app: A onDragDown
01-31 20:50:04.030 16868-16868/com.example.harmonyapp E 00001/app: B onDragPreAccept
01-31 20:50:04.030 16868-16868/com.example.harmonyapp E 00001/app: B onDragStart
01-31 20:50:04.030 16868-16868/com.example.harmonyapp E 00001/app: B onDragUpdate
01-31 20:50:04.031 16868-16868/com.example.harmonyapp E 00001/app: A onDragCancel
01-31 20:50:04.032 16868-16868/com.example.harmonyapp E 00001/app: B onDragUpdate
01-31 20:50:04.147 16868-16868/com.example.harmonyapp E 00001/app: B onDragUpdate
01-31 20:50:04.150 16868-16868/com.example.harmonyapp E 00001/app: B onDragEnd

A不拦截,B拦截消费

01-31 20:51:14.986 18818-18818/com.example.harmonyapp E 00001/app: B onDragDown
01-31 20:51:14.987 18818-18818/com.example.harmonyapp E 00001/app: A onDragDown
01-31 20:51:15.021 18818-18818/com.example.harmonyapp E 00001/app: B onDragPreAccept
01-31 20:51:15.021 18818-18818/com.example.harmonyapp E 00001/app: A onDragPreAccept
01-31 20:51:15.021 18818-18818/com.example.harmonyapp E 00001/app: A onDragStart
01-31 20:51:15.021 18818-18818/com.example.harmonyapp E 00001/app: A onDragUpdate
01-31 20:51:15.022 18818-18818/com.example.harmonyapp E 00001/app: B onDragCancel
01-31 20:51:15.022 18818-18818/com.example.harmonyapp E 00001/app: A onDragUpdate
01-31 20:51:15.335 18818-18818/com.example.harmonyapp E 00001/app: A onDragUpdate
01-31 20:51:15.348 18818-18818/com.example.harmonyapp E 00001/app: A onDragEnd

效果图
Alt
源码地址
https://gitee.com/liukerui/harmony-app-examples.git

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值