How to create image animation by rotating, with decreasing speed, until it stops

Asked

Viewed 293 times

2

I have this animation below in which an Imagemview rotates on its axis for 4 seconds. It rotates even with the same speed the 4 seconds.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
    <rotate
        android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="4000"
        android:startOffset="0"/>
</set>

How do I make an animation that starts by rotating normally but decreases until it stops in the same 4 seconds. Example: A car tire. It’s spinning, but when you brake the car, this tire slows down until it stops completely?

  • ramaral, it worked out! And I wasn’t going to find out any sooner. I started about 20 hours trying to solve it, it was 4 in the morning and I couldn’t. It’s because I’m going the other way... I used Handler, I used for(...) varying setStartOffset, etc. Thank you very much... Hugs...

1 answer

3


The animation is achieved by varying a characteristic, in this case the rotation.

How this characteristic varies over time is determined by Interpolator used.

So, if you want there to be a deceleration, instead of a linearinterpolator, use a Decelerateinterpolator

<?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/decelerate_interpolator">
        <rotate
            android:fromDegrees="0"
            android:toDegrees="360"
            android:pivotX="50%"
            android:pivotY="50%"
            android:duration="4000"
            android:startOffset="0"/>
    </set>
  • Now a problem has arisen, which is speed. If you use 1 second it turns very fast to stop. If you use 10 seconds it rotates very slowly until it stops, that is, the animation uses a fixed number of turns. How to increase this amount of spins to when using 10 seconds start with the same usage speed with 1 second?

  • 1

    The number of revolutions is determined by the value assigned to android:toDegrees. Use a 360 multiple: 1x360 one lap, 2x360 two laps, ...... .

  • Ramaral, now I saw that I had not commented on your answer yet (since April). It worked. Obg...

  • 1

    Enough, as you did; accept the answer to know it was useful.:)

  • I’ll always do it now...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.