0
点赞
收藏
分享

微信扫一扫

Android_code_多点触摸


/** 根据打印发现:即使没有移动也一直在发送移动的事件 */
public void handleMultiTouchEvent01(MotionEvent e) {

final int action = e.getActionMasked();
final int actionIndex = e.getActionIndex();
int x, y;

switch (action) {

// 第一个 手指 初次接触到屏幕 时触发。
case MotionEvent.ACTION_DOWN:

// 记录初始化的坐标
x = (int) (e.getX() + 0.5f);
y = (int) (e.getY() + 0.5f);
Logcat.d(TAG, String.format("DOWN index: %d x: %d y: %d", actionIndex, x, y));
break;

// 有非主要的手指按下(即按下之前已经有手指在屏幕上)。
case MotionEvent.ACTION_POINTER_DOWN:

x = (int) (e.getX(actionIndex) + 0.5f);
y = (int) (e.getY(actionIndex) + 0.5f);
Logcat.d(TAG, String.format("DOWN index: %d x: %d y: %d", actionIndex, x, y));

break;

// 手指 在屏幕上滑动 时触发,会多次触发。
case MotionEvent.ACTION_MOVE:

for (int i = 0; i < e.getPointerCount(); i++) {
x = (int) (e.getX(i) + 0.5f);
y = (int) (e.getY(i) + 0.5f);
Logcat.d(TAG, String.format("MOVE index: %d x: %d y: %d", i, x, y));
}

break;

// 有非主要的手指抬起(即抬起之后仍然有手指在屏幕上)。
case MotionEvent.ACTION_POINTER_UP:

x = (int) (e.getX(actionIndex) + 0.5f);
y = (int) (e.getY(actionIndex) + 0.5f);
Logcat.d(TAG, String.format("UP index: %d x: %d y: %d", actionIndex, x, y));
break;

// 最后一个 手指 离开屏幕 时触发。
case MotionEvent.ACTION_UP:
x = (int) (e.getX(actionIndex) + 0.5f);
y = (int) (e.getY(actionIndex) + 0.5f);
Logcat.d(TAG, String.format("UP index: %d x: %d y: %d", actionIndex, x, y));
break;

}


}


举报

相关推荐

0 条评论