如何找到画布中绘制的矩形的中心坐标?我唯一的项目是left,right,bottom和top值。
Rect newRect = new Rect(left, top, right, bottom);
canvas.drawRect(newRect, paint);
答案 0 :(得分:3)
center = 0.5(左+右),0.5(下+上)
答案 1 :(得分:3)
Rect newRect = new Rect(left, top, right, bottom);
canvas.drawRect(newRect, paint);
int xCenter = newRect.centerX();
int yCenter = newRect.centerY();
或者,如果您需要浮点值以获得更好的精确度,请使用exactCenterX()和exactCenterY()
float xCenter = newRect.exactCenterX();
float yCenter = newRect.exactCenterY();