I’m new to Android development and am trying to figure out how to continuously rotate an image using the onTouchEvent. I am using the following code to rotate the image 10 degrees when the onTouchEvent detects a screen touch and vice versa, but I want the image to keep rotating in 10 degree intervals as long as the onTouchEvent occurs. Thanks!
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN) {
degrees=degrees+10;
make(degrees);
}
else if(event.getAction()==MotionEvent.ACTION_UP) {
degrees=degrees-10;
make(degrees);
}
return super.onTouchEvent(event);
}
}
From what I understand, is you want to start rotating an image when the user puts his / her finger on the screen, and stop rotating when the user takes off the finger from the screen.
If that’s correct, you’d need to start a thread or a handler on the background that would keep.
May be something like: