0
나는 하나의 샘플 안드로이드 프로젝트 다이얼 패드를 만들어 사용자가 임의의 숫자를 누르면 해당 값을 잡아야하므로 사용자가 한 번에 두 개의 버튼을 누를 때 어떻게 그 두 개의 버튼 값을 얻을 수 있는지 터치 이벤트 사용버튼에 멀티 터치를 처리하는 방법
나는 하나의 샘플 안드로이드 프로젝트 다이얼 패드를 만들어 사용자가 임의의 숫자를 누르면 해당 값을 잡아야하므로 사용자가 한 번에 두 개의 버튼을 누를 때 어떻게 그 두 개의 버튼 값을 얻을 수 있는지 터치 이벤트 사용버튼에 멀티 터치를 처리하는 방법
Making Sense of Multitouch을 참조하십시오, 그것은 나를 많이 도왔던 정말 좋은 기사입니다. 기본적으로
는 당신이 시도
private static final int INVALID_POINTER_ID = -1;
// The ‘active pointer’ is the one currently moving our object.
private int mActivePointerId = INVALID_POINTER_ID;
// Existing code ...
@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN: {
final float x = ev.getX();
final float y = ev.getY();
mLastTouchX = x;
mLastTouchY = y;
// Save the ID of this pointer
mActivePointerId = ev.getPointerId(0);
break;
}
case MotionEvent.ACTION_MOVE: {
// Find the index of the active pointer and fetch its position
final int pointerIndex = ev.findPointerIndex(mActivePointerId);
final float x = ev.getX(pointerIndex);
final float y = ev.getY(pointerIndex);
final float dx = x - mLastTouchX;
final float dy = y - mLastTouchY;
mPosX += dx;
mPosY += dy;
mLastTouchX = x;
mLastTouchY = y;
invalidate();
break;
}
case MotionEvent.ACTION_UP: {
mActivePointerId = INVALID_POINTER_ID;
break;
}
case MotionEvent.ACTION_CANCEL: {
mActivePointerId = INVALID_POINTER_ID;
break;
}
case MotionEvent.ACTION_POINTER_UP: {
// Extract the index of the pointer that left the touch sensor
final int pointerIndex = (action & MotionEvent.ACTION_POINTER_INDEX_MASK)
>> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
final int pointerId = ev.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose a new
// active pointer and adjust accordingly.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mLastTouchX = ev.getX(newPointerIndex);
mLastTouchY = ev.getY(newPointerIndex);
mActivePointerId = ev.getPointerId(newPointerIndex);
}
break;
}
}
return true;
}
처럼 버튼의 onTouch를 재정의해야합니다 http://android-developers.blogspot.co.il/2010/06/making-sense-of-multitouch.html –
각 버튼마다 별도의 onClickListener를 설정하십시오. – Abx
사용해보기 : http://stackoverflow.com/questions/5346148/android-work-multitouch-button – Android