【问题标题】:MotionEvent.obtain() Multitouch Event for API < 9MotionEvent.obtain() API < 9 的多点触控事件
【发布时间】:2013-05-20 00:33:51
【问题描述】:

我正在尝试使用MotionEvent.obtain() 模拟多点触控事件。这可以使用 API9 和 API14 中引入的方法来完成:

API 9:
public static MotionEvent obtain (long downTime, long eventTime, int action, int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags, int source, int flags)
API 14:
public static MotionEvent obtain (long downTime, long eventTime, int action, int pointerCount, PointerProperties[] pointerProperties, PointerCoords[] pointerCoords, int metaState, int buttonState, float xPrecision, float yPrecision, int deviceId, int edgeFlags, int source, int flags)

但是,我的应用程序需要支持 API >= 7。该 API 下面的最新方法是

API 5:
public static MotionEvent obtain (long downTime, long eventTime, int action, int pointerCount, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags)

它接受 pointerCount,但只接受其中一个指针的坐标。所以我不确定如何使用这种方法来模拟多点触控。

有什么想法吗?

【问题讨论】:

  • 检查正在使用的版本,并调用适当的版本。当然,您也可以只使用最旧的版本,不推荐使用并不意味着它不起作用 - 这意味着他们希望让人们摆脱它并可能在遥远的将来将其删除,但目前保留它是为了向后兼容.它仍然可以使用。

标签: android testing multi-touch


【解决方案1】:

回答我自己的问题:使用 API

因此,我在多点触控测试中使用 @TargetApi(android.os.Build.VERSION_CODES.GINGERBREAD) 跳过了 API

【讨论】:

    猜你喜欢
    • 2011-03-16
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2014-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多