2011-10-19 16 views
0

私はキャンバスアンドロイドに2つの疑問があります。アンドロイドのキャンバスに円drwanの位置(x座標とy座標)を取得する方法は?

これらは以下に説明する。まず

、私はキャンバス上の円の行を集めていたが、私は描くことができるように描かれて(一つだけ円周上)円のx、y座標をキャプチャしますサークル上のビットマップ(中央)。

第2に、私はサークルのタッチイベントを暗示したいです。つまり、ある人がタッチすると色を変えたいと思います。

+0

「私がしたいですxとyの座標をキャプチャします... "円を描いたときの座標はありました。後で使うことができるように座標をつかんでいないのはなぜですか? – mbeckish

+0

「サークル上にビットマップを描画する」とはどういう意味ですか? – ligi

答えて

0

まず、サークルゾーンのGridSectorクラスを作成する必要があります。

public class GridSector { 

    private int x = 0; 
    private int y = 0; 
    private Rect rect = new Rect(0, 0, 0, 0); 

    public GridSector(int x, int y, Rect rect) { 
     this.x = x; 
     this.y = y; 
     this.rect = rect; 
    } 

    public int getX() { 
     return x; 
    } 

    public int getY() { 
     return y; 
    } 

    public Rect getRect() { 
     return rect; 
    } 

    public void setRect(Rect rect) { 
     this.rect.set(rect.left, rect.top, rect.right, rect.bottom); 
    } 
} 

次に、お望みのものを表示するビューを作成します。 #2の

public class GridSectorsView extends View { 


     GridSector currentSelectedSector; 
     @Override 
      protected void onDraw(Canvas canvas) { 
       super.onDraw(canvas); 
       drawCircle(canvas); // draw your circles; 
      } 

      @Override 
      public boolean onTouchEvent(MotionEvent ev) { 
       switch (ev.getAction()) { 
        case MotionEvent.ACTION_DOWN: { 
        invalidate(currentSelectedSector.getRect()); // update your circles (call onDraw Function) ; 
       } 
      } 
} 
+0

それを説明できますか?私はアンドロイドに新しいので – userRav

+0

正確に何を説明しますか? – Yahor10

1

: は、あなたのポイントの中心とタッチイベントの間の距離を計算 - 距離があなたの円の半径よりも小さい場合 - あなたがサークルに押され

関連する問題