Rotate animation is a special kind of animation in Android which controls the Rotation of an object. These type of animations are usually used by developers to give a feel to the user about the changes happening in the application like loading content, processing data, etc. By using the rotate animation effect, an object can be rotated in the X-Y plane of activity and it allows the rotation in both Clockwise and Anticlockwise direction.
The class hierarchy of RotateAnimation class in Kotlin
XML attributes which define the rotation of an object
|android:pivotX||To define the X coordinate of the point about which the object is being rotated|
|android:pivotY||To define the Y coordinate of the point about which the object is being rotated|
|android:fromDegrees||Rotation of the object starts from this geomertical degree|
|android:toDegrees||Rotation of the object ends at this geomertical degree|
|android:duration||Used to define the duration of the animation in millisecond|
|android:startOffset||Used to delay the animation time in millisecond|
This example demonstrates the steps involved in implementing the clockwise and anticlockwise rotation animation to an image file. An image file will be added in the activity using ImageView.
Note: The steps are performed on Android Studio version 4.0
Step 1: Create a New Project
- Click on File, then New => New Project.
- Select language as Kotlin.
- Select the minimum SDK as per your need.
Step 2: Modify activity_main.xml file
Below is the code for
activity_main.xml file to add a TextView, ImageView and 2 buttons in an activty.
Step 3: Define XML file for clockwise and anticlockwise rotation of the image
Create a new directory in the res folder of the application and name it anim. In this directory create 2 Animation Resource File namely
rotate_anticlockwise. These 2 files are the XML file which holds the details of the animation. Below is the code for both the file.
Step 4: Modify MainActivity.kt File
Below is the code for
MainActivity.kt file to load and start animation on the ImageView widget according to the button clicked by the user.
Step 5: Modify strings.xml File
All the strings which are used in the activity are listed in this file.
Run as Emulator
- Android Animations in Kotlin
- How to make Check/Tick and Cross animations in Android
- Android Animations using Java
- jQuery | Stop Animations
- AngularJS | Animations
- How to run two animations simultaneously in jQuery ?
- How to dynamically create '@-Keyframe' CSS animations?
- Why Kotlin will replace Java for Android App Development
- Android EditText in Kotlin
- Android Toast in Kotlin
- Android Fade In/Out in Kotlin
- Android Slide Up/Down in Kotlin
- Android progress notifications in Kotlin
- Kotlin Android Tutorial
- Difference between Java and Kotlin in Android with Examples
- How to send message on WhatsApp in Android using Kotlin
- Thread Priority in Kotlin & Android
- Running User Interface Thread in Android using Kotlin
- How to Add RangeSeekbar in Android Using Kotlin?
- Android WebView in Kotlin
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.