2016-10-04 14 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);

関連する問題