如果MotionEvent
函数中有onInterceptTouchEvent
个事件,是否可以计算运动长度?
有人可以帮帮我吗?
答案 0 :(得分:2)
是的,这是可能的。
public double calcLength(MotionEvent event) {
int historySize = event.getHistorySize();
float x1 = event.getHistoricalX(0);
float y1 = event.getHistoricalY(0);
float x2 = event.getHistoricalX(historySize - 1);
float y2 = event.getHistoricalY(historySize - 1);
// calculate distance between (x1,y1) & (x2,y2)
return Math.sqrt(Math.pow(y2-y1, 2) + Math.pow(x2-x1, 2));
}