My imageview consists of circle wheel as shown in below pic.I want that wheel should start rotating as soon as user presses a start button and stop rotating when user presses stop button.Is it possible programmatically?If yes,how can i do that?
Asked
Active
Viewed 2,097 times
2
-
Possibly Duplicate Que : http://stackoverflow.com/questions/2032304/android-imageview-animation – Pratik Patel May 02 '15 at 08:13
-
Have you checked my answer? – Bojan Kseneman May 06 '15 at 15:07
-
@BojanKseneman yupp.correct answer..thankuu – May 06 '15 at 17:49
1 Answers
3
Create a file named clockwise_rotation.xml and put it into /res/anim
Change the duration according to your needs.
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="3500"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:startOffset="0"
android:toDegrees="360"
/>
And make these two functions that you will be calling in your two buttons
private void startAnimation(){
Animation rotation = AnimationUtils.loadAnimation(getContext(), R.anim.clockwise_rotation);
mImageView.startAnimation(rotation);
}
private void stopAnimation(){
mImageView.clearAnimation();
}

Bojan Kseneman
- 15,488
- 2
- 54
- 59