2013-05-20 50 views
0

我在嘗試使用MotionEvent.obtain()來模擬多點觸控事件。MotionEvent.obtain()針對API的多點觸控事件<9

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) 

它不接受:這可以通過在API9介紹的方法和API14完成pointerCount,但只接受其中一個指針的座標。所以我不確定如何使用這種方法來模擬多點觸控。

任何想法?

+0

檢查正在使用的版本,並調用相應的版本。當然,你也可以使用最老的版本,不推薦使用,這並不意味着它不會工作 - 這意味着他們想讓人們遠離它,並可能在遙遠的將來將其刪除,但目前正在保持它的向後兼容性。它仍然可以使用。 –

回答

0

回答我的問題:這是不可能生成表示多觸摸事件MotionEvents使用MotionEvent.obtain()從API < 9.

因此我簡單地跳過API < 9的裝置(即含有約多個指針信息)在我的多點觸控測試中使用@TargetApi(android.os.Build.VERSION_CODES.GINGERBREAD)