I want to rotate a picture (Bitmap within a ImageView) around his center.
This works pretty well by using the preRotate method with the values width/2 and height/2 of the Bitmap and 1 or -1 degree as rotation factor.
But I implemented the rotation functions as Buttons. Everytime the Button “rotate right” is pressed the Imageview rotates one degree to the right and so on. It would be nice to press the Button and while the Button is pressed the picture starts rotating until the button is released.
I’ve read some threads here in which these feature is implemented as OnTouchListener instead of OnClickListener, but it does not work for me. If I implement loops within the MotionEvent.ACTION_DOWN event then they are infinite. If I don’t use loops then the event is only handled once (like in OnClickListener).
So how can I increment/decrement the rotation factor while a button is pressed?
Short answer: You need to implement a corresponding MotionEvent.ACTION_UP to stop the adding. ACTION_DOWN is only ever fired once, when the user presses down. That’s why when you weren’t looping you only got one increment. What you need is a seperate thread to start doing the increments when a MotionEvent.ACTION_DOWN is done and stop them when MotionEvent.ACTION_UP is fired. Something like this should work.