我想知道如何使用单点触控手势旋转位图图像。请帮助并提出一些解决方案。我在
的帮助下完成了位图的缩放http://grishma102.blogspot.in/2013/10/drag-and-drop-functionality-to-move.html。现在我需要在触摸和旋转调整大小按钮的同时旋转整个图像。如何实现它?
提前致谢
答案 0 :(得分:5)
答案 1 :(得分:0)
用一根手指处理旋转的功能,主要思想是计算视图的centerX和centerY,并考虑状态栏高度(如果使用的话)。
@Override
public boolean onTouch(View view, MotionEvent event) {
switch (action) {
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_DOWN:
rotateX = event.getRawX();
rotateY = event.getRawY();
centerX = view.getX() + ((View) getParent()).getX() + (float) view.getWidth() / 2;
centerY = view.getY() + statusBarHeight + (float) view.getHeight() / 2;
break;
case MotionEvent.ACTION_MOVE:
newRotateX = event.getRawX();
newRotateY = event.getRawY();
double angle = Math.atan2(event.getRawY() - centerY, event.getRawX() - centerX) * 180 / Math.PI;
view.setRotation((float) angle - 45);
rotateX = newRotateX;
rotateY = newRotateY;
}
}
return true;
}
};