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.我正在保存在画布上绘制的圆圈的这些坐标,这是为了标记汽车上的损坏。 但是当我使用这些值显示在更大的设备上时,圆圈位置并不完整..可以做什么?
答案 0 :(得分:1)
所有坐标都参考设备,屏幕由像素和每英寸像素确定。
我希望这有助于您重新思考问题。