我通过在onTouchListener
上实现image-view
来旋转图像。一切正常,但是当图像达到0度或180度(水平中心)时,我想停止图像旋转。
这是我用来旋转图像的示例代码
ImageView view = (ImageView) v;
if (mode == ZOOM)
{
float newDist = spacing(event);
if (newDist > 5f) {
matrix.set(savedMatrix);
float tScale = newDist / oldDist;
matrix.postScale(tScale, tScale, mid.x, mid.y);
}
//Rotate the image
if (lastEvent != null) {
newRot = rotation(event);
float r = newRot - d;
matrix.postRotate(r, view.getMeasuredWidth() / 2,
view.getMeasuredHeight() / 2);
}
}
private float rotation(MotionEvent event) {
double delta_x = (event.getX(0) - event.getX(1));
double delta_y = (event.getY(0) - event.getY(1));
double radians = Math.atan2(delta_y, delta_x);
return (float) Math.toDegrees(radians);
}
此代码正在旋转图像,但我想向用户表明您的图像在center_horizontal
处对齐。
感谢您的帮助。