2

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?

enter image description here

1 Answers1

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