我目前正在为 Android 上的多点触摸事件实现手势检测器。为了测试检测器的行为,我想将 MotionEvents 发送到检测器并检查他的 Action 。
我目前遇到的问题是我只能通过调用现有的 MotionEvent.obtain()
方法之一来创建 MotionEvents,但这些方法似乎不允许我设置指针 ID对于一个事件。 IE。我只能创建单点触摸事件。
有谁知道是否有可能以某种方式做到这一点?我可以使用另一个数据结构作为检测器的输入,但如果可能的话我想避免这种情况并坚持使用 MotionEvent 类。
最佳答案
你试过吗:
public static MotionEvent obtain (long downTime, long eventTime, int action,
int pointers, int[] pointerIds, PointerCoords[] pointerCoords, int metaState,
float xPrecision, float yPrecision, int deviceId, int edgeFlags, int source, int flags)
这是 MotionEvent page 中列出的第三个 obtain() 方法
您可以指定:
- pointers - 点数 将参加此次 Activity 。
- pointerIds - 指针数组 提供标识符的值 每个指针。
- pointerCoords - 指针数组 值(value)观提供 MotionEvent.PointerCoords坐标 每个指针的对象。
关于android - 生成用于测试的多点触控 MotionEvents,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3637044/