我想知道如何用android中的onTouch()事件顺时针和逆时针旋转图像。以及如何通过onTouchListener找出它是顺时针还是逆时针旋转?由于如何在android中顺时针和逆时针旋转图像?
2
A
回答
0
基本上你可以将你的形象自己的类,扩展视图,并实现OnClickListener像这里面:
public class CustomImageView extends View implements OnClickListener{
...
}
覆盖您CustomImageView类中的方法的onDraw。旋转可以通过旋转画布对象在onDraw内部实现。
第三,实现onClick以获得点击事件并根据您的需要进行轮换。
的基本布局可能看起来像:
public class CustomImageView extends View implements OnClickListener{
public void onClick (View v){
// process click here
// invalidate after click processing in order to redraw
this.invalidate();
}
protected void onDraw(Canvas canvas) {
// draw your image here, might be bitmap or other stuff
// rotate canvas now, your logic on clockwise or
// counterclockwise rotation goes here
canvas.rotate(-90.0f, centerx, centery);
}
}
0
您可以尝试使用此功能得到x和从MotionEvent对象的y值的旋转。 在那里,我仍然需要从给定的矢量x和矢量y的附加计算中找到方向。
private int calculateAngle(float GETX, float GETY) {
int direction = 1;
double tx = (int) GETX - object_center.x;
double ty = (int) GETY - object_center.y;
double angleInDegrees = Math.atan2(ty, tx) * 180/Math.PI;
int area = 0;
int ACTUAL_ANGLE = 270;
if (angleInDegrees < 0 && angleInDegrees < -90) {
// Need to add
// 270+angle degrees
// =================
ACTUAL_ANGLE += (int) (180 + angleInDegrees) * direction;
} else if (angleInDegrees < 0 && angleInDegrees > -90) {
// Need to add
// 90+angle degrees
// =================
ACTUAL_ANGLE = (int) (90 + angleInDegrees);
} else if (angleInDegrees > 0)
ACTUAL_ANGLE = 90 + (int) angleInDegrees;
return ACTUAL_ANGLE;
}
相关问题
- 1. 顺时针/逆时针旋转图像
- 2. 顺时针和逆时针方向旋转图像
- 3. 如何在jQuery中滚动/顺时针和逆时针旋转图像?
- 4. CSS3 - 顺时针旋转比逆时针
- 5. 如何在android中(在指尖旋转)顺时针和逆时针旋转图像?
- 6. jQuery:以90度增量顺时针/逆时针旋转图像?
- 7. 如何顺时针和逆时针旋转圆圈?
- 8. 使用c中的平移变换顺时针和逆时针旋转图像#
- 9. JQuery-顺时针旋转div并逆时针旋转
- 10. 如何顺时针或逆时针旋转图像,以较短者为准?
- 11. 如何顺时针旋转图像?
- 12. 在android中顺时针和逆时针方向旋转一个正方形
- 13. 带8弧的圆弧svg顺时针和逆时针旋转
- 14. 如何在android中执行顺时针和逆时针手势
- 15. Javascript旋转 - 如何逆时针旋转?
- 16. 使用javascript在div内顺时针或逆时针旋转图像
- 17. 识别顺时针或逆时针旋转
- 18. 查找QDial是否顺时针或逆时针旋转
- 19. Flash CS4:顺时针或逆时针旋转对象
- 20. 旋转阵列逆时针
- 21. 使用LibGDX顺时针旋转图像
- 22. 顺时针旋转90度的图像
- 23. Kineticjs - 顺时针旋转图像90度
- 24. 如何在逆时针旋转后重建图像
- 25. 如何检测cgaffinetransformrotate方法是顺时针还是逆时针旋转?
- 26. 试图顺时针旋转90度的二维数组,但它会逆时针
- 27. Java PathIterator顺时针或逆时针?
- 28. 目标C CATransform3DMakeRotation顺时针/逆时针
- 29. 顺时针旋转线
- 30. 旋转阵列顺时针
使用旋转动画,也有很多很好的例子在那里...... http://developer.android.com/reference/android/view/animation/RotateAnimation.html – testingtester 2012-04-22 08:54:46
谢谢,但我想知道在android中使用onTouch()事件顺时针和逆时针旋转图像的方式 – secretlm 2012-04-22 09:01:17