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;
}
私は自分の座標を見ることができるの周りの子供のキャンバス上に四角形を描画することにより、正しく変換されますタッチポイント。
期待される座標と観測された座標 – suku