2016-10-04 6 views
0

저는 모든 접촉을 처리하고 자식 뷰로 구현 된 onTouch를 호출하여 자식에 대한 이벤트의 일부를 트래버스합니다 (필요한 경우). 문제는 컨테이너가 자신의 좌표계와 자녀의 CS.Here로 번역 할 필요는 컨테이너의 코드입니다 :컨테이너의 좌표 공간에서 자식 좌표로 좌표를 변환합니다.

@Override 
public boolean onTouchEvent(MotionEvent event) { 
//handle some gestures 
    .... 
    //traverse motion event so container's children can handle it 
    if(numFingers==1) 
     content.onTouch(content,event); 
    return true; 
} 

자녀의 코드 :

public boolean onTouch(View v, MotionEvent event) { 
    //get child's tranformation 
    Matrix m=this.getMatrix(); 
    float[] coords=new float[2]; 
    //get touch coords 
    coords[0]=event.getX(); 
    coords[1]=event.getY(); 
    //translate it to child's coordinates 
    m.mapPoints(coords); 
    PointF p =new PointF(coords[0],coords[1]); 
    Piece piece=getPieceUnderPoint(p); 
    if (piece!=null) 
     Log.d("game field3",piece.i+","+piece.j); 
    return true; 
} 
나는 주위 자녀의 캔버스에 그리기 사각형으로 잘못 번역 내 좌표를 볼 수 있습니다

터치 포인트.

+0

예상 좌표와 관측 좌표를 게시 할 수 있습니까? – suku

답변

0

해결책은 터치 좌표에 적용하기 전에 변환 행렬을 반전시켜야한다는 것입니다. m.invert (m);

관련 문제