안드로이드 개발 질문/답변
(글 수 45,052)
멀티터치를 구현하고자 합니다.
예전에
간단하게 쓰자면
x1 = (int)event.getX(0);
x2 = (int)event.getY(1);
action = event.getAction();
이런식으로 구현을 하고
action을 통해 현재 업, 다운, 무브를 멀티를 판단하고 했는데
멀티터치 중에 여러 액션을 할 경우 제대로 반영이 안되더라구요.
인터넷으로 찾아보니
int actionPointerId = action & MotionEvent.ACTION_MASK;
int actionEvent = action & MotionEvent.ACTION_MASK;
int pointerIndex = event.findPointerIndex(actionPointerId);
xPos = (int)event.getX(pointerIndex);
yPos = (int)event.getY(pointerIndex);
이런류로 멀티터치를 구현한 것이 있던데
전 각각의 좌표를 따로 갖고싶어서
int X[] = new int[2];
int Y[] = new int[2];
X[pointerIndex] = (int)event.getX(pointerIndex);
Y[pointerIndex] = (int)event.getY(pointerIndex);
이런식으로 넣었는데
에러가 나네요,
(배열의 수를 늘려도 에러가 납니다.
java.lang.ArrayIndexOutOfBoundsException
at android.view.MotionEvent.getX(MotionEvent.java.733)
X[pointerIndex] = (int)event.getX(pointerIndex);
포인터 인덱스 값이 문제인거 같은데 잘모르겠네요.
멀티터치의 값을 각각의 변수로 따로 관리 하려면 어떻게 해야 하나요?




안녕하세요. 저도 멀티터치때문에 많은 검색을 해봤습니다.
PointF point0 = new PointF(event.getX(0), event.getY(0));
PointF point1 = new PointF(event.getX(1), event.getY(1));
보통(?) 위와 같이 PointF를 사용한 소스들을 많이 봐왔습니다.
제가 보기에도 X, Y를 따로 가지고 다닐필요 없이 PointF를 사용하시면 좀더 보기에 편하지 않을까 생각됩니다.