2017-03-29 2 views
0
class Draw extends View { 
    private Paint mPaint; 
    public Button mCircles; 

    DrawFragment mDrawFragment; 
    private Circle mCurrentCircle; 
    private List<Circle> mCircle= new ArrayList<>(); 

    public Draw(Context context){ 
     this(context,null); 
    } 

    public Draw(Context context, AttributeSet attrs) { 
     super(context, attrs); 

     mPaint=new Paint(); 
     mPaint.setColor(Color.RED); 
     mPaint.setAlpha(80); 
    } 

    @Override 
    protected void onDraw(Canvas canvas) { 
     super.onDraw(canvas); 

     for (Circle circle : mCircle) { 
      float x1 = circle.getCenter().x; 
      float x2 = circle.getFinal().x; 
      float y1 = circle.getCenter().y; 
      float y2 = circle.getFinal().y; 

      double radius = Math.sqrt(Math.pow(dpx1 - dpx2, 2) + Math.pow(dpy1 - dpy2, 2)); 

      float rad = (float) radius; 

      canvas.drawCircle(dpx1, dpy1, rad, mPaint); 
     } 

     switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
       mCurrentCircle = new Circle(current); 
       mCircle.add(mCurrentCircle); 
       break; 

      case MotionEvent.ACTION_MOVE: 
       if (mCurrentCircle != null) { 
        mCurrentCircle.setFinal(current); 
        invalidate(); 
       } 
       break; 

      case MotionEvent.ACTION_UP: 
       mCurrentCircle = null; 
       invalidate(); break; 
     } 

    } 

    Log.i(TAG, "onTouchEvent: at x="+current.x + ", y =" + current.y); 

    return true; 
} 

1.キャンバスに描画された円の座標を保存しています。これは車に損傷をマークするためのものです。 しかし、これらの値を使ってより大きなデバイスに表示すると、サークルの位置は元に戻りません。何ができるのですか?Androidの座標を保存するキャンバス別のデバイスに円を描くと表示する

答えて

0

すべての座標は、ピクセルと1インチあたりのピクセルで決まる画面のデバイスを参照します。

  • 別のデバイスで同じ情報を使用する場合は、参考になるアンカーポイントの種類を設定する必要があります。
  • たとえば、サークルを車の背景画像に描画する場合は、その画像の位置にテーマを参照できるはずです。
  • これらの情報を使用すると、他のデバイスでは、座標がデバイスに参照されずに車のイメージを参照しているため、どのデバイスでもそのサークルを再描画できます。

私はこれがあなたの問題を再考するのに役立つことを願っています。

関連する問題