答案 0 :(得分:0)
您可以使用画布旋转。
//Example
Path path = new Path();
path.addRect(166, 748, 314, 890, Path.Direction.CW);
canvas.save(); // first save the state of the canvas
canvas.rotate(45); // rotate it
canvas.drawPath(path, paint); // draw on it
canvas.restore(); // restore previous state (rotate it back)
Android Implement onTouchListener on path objects
检查此链接。你可以override onTouchEvent()
答案 1 :(得分:0)
确定旋转角度的一般方法:
rotation center coordinates xc, yc
on touch (mouse) down:
check whether touch point is in grab region
remember coordinates x0, y0
set flag "InRotation"
on touch move:
current coordinates x1, y1
check if (they are in allowed region) and (InRotation is set)
calculate rotation angle as
alpha = Math.atan2((x1-xc)*(y0-yc) - (x0-xc)*(y1-yc),
(x1-xc)*(x0-xc) + (y0-yc)*(y1-yc))
redraw image using alpha angle
on touch up:
clear InRotation flag
make actions after rotation if needed
请注意,必须在仿射矩阵计算中使用旋转中心坐标才能正确绘制旋转的矩形:
canvas.save();
canvas.rotate(alpha, xc, yc);
canvas.drawRect(.....);
canvas.restore();