I use imageView to implement a steering wheel in Android just simulate the real one in the car.

I use the code from the reference

rotating-dialer

，everything go well, but I have to limit the steering wheel to rotate between -360 ~ +360 .

I defined a variable TotalAngle to keep the rotated degree，the original position is 0 degree,and clockwise rotated the variable increase otherwise decrease。

when the variable TotalAngle = 360 it should stop rotate clockwise but can rotate counterclockwise . if = -360 just the opposite. How can I stop the rotate,

the core code of my rotate steering wheel:

`` case MotionEvent.ACTION_DOWN:double startX,startY;startX = event.getX();startY = event.getY();sx = startX - (dialerWidth / 2d);sy = dialerHeight - startY - (dialerHeight / 2d);startAngle = gwgetAngle(sx, sy);break;case MotionEvent.ACTION_MOVE:double cstartX,cstartY;cstartX = event.getX();cstartY = event.getY();cx = cstartX - (dialerWidth / 2d);cy = dialerHeight - cstartY - (dialerHeight / 2d);double currentAngle = gwgetAngle(cx, cy);double rotateDegree = startAngle - currentAngle;if ((sx * cy - sy * cx) > 0 ? true : false) { //judge for directionLog.i("counterclockwise", ".........counter");if (rotateDegree > 0) {totalAngle += rotateDegree - 360;Log.i("totalAngle**", "....." + totalAngle);} else {totalAngle += rotateDegree;Log.i("totalAngle", "********" + totalAngle);}} else {Log.i("clockwise", "......clockwise");if (rotateDegree < 0) {totalAngle += rotateDegree + 360;Log.i("totalAngle~~", "" + totalAngle);} else {totalAngle += rotateDegree;Log.i("totalAngle", "~~~~~~~~~~~" + totalAngle);}}rotateDialer((float) rotateDegree);startAngle = currentAngle;sx = cx;sy = cy;break;``

everything goes well except for the stop point,yes it can stop at a point,but the point always changes,I don't how to fix it?

I saw a similar question:stop rotate question, fail to figure it out ..

the answer's logic is correct,but how to realize it in code？

When traveledAngle becomes greater than 360' you need to stop rotating in clockwise direction, and when it becomes less than 0, you need to stop rotating in counter clockwise direction.

I need the value of traveledAngle just right be 360 and stop rotate，in my opinion I cannot figure it in the MotionEvent‘s action_move ？

Top