android 如何在ACTION_MOVE算出手指在屏幕上拖动的距离,和拖动的时间

2025-04-16 05:38:01
推荐回答(1个)
回答1:

switch (action) {
case MotionEvent.ACTION_DOWN:
DownX = event.getX();//float DownX
DownY = event.getY();//float DownY
currentMS = System.currentTimeMillis();//long currentMS 获取系统时间
break;
case MotionEvent.ACTION_MOVE:
float moveX = event.getX() - DownX;//X轴距离
float moveY = event.getY() - DownY;//y轴距离
long moveTime = System.currentTimeMillis() - currentMS;//移动时间
break;
case MotionEvent.ACTION_UP:
break;
}