Animation is a method in which a collection of images are combined in a sepecific way and processed then they appear as moving images. Building animations make on-screen objects seems to be alive. Android has quite a few tools to help you create animations with relative ease. so in this article we will learn to create animations using Kotlin. below are some attributes which we are using while writing the code in xml.
Table of Attributes :
|android:duration||It is used to specify the duration of animation to run|
|android:fromAlpha||It is the starting alpha value for the animation,
where 1.0 means fully opaque and 0.0 means fully transparent
|android:toAlpha||It is the ending alpha value|
|android:id||Sets unique id of the view|
|android:fromYDelta||It is the change in Y coordinate to be applied at the start of the animation|
|android:toYDelta||It is the change in Y coordinate to be applied at the end of the animation|
|android:startOffset||Delay occur when an animation runs (in miliseconds), once start time is reached.|
|android:pivotX||It represents the X-axis coordinates to zoom from starting point.|
|android:pivotY||It represents the Y-axis coordinates to zoom from starting point.|
|android:fromXScale||Starting X size offset,|
|android:fromYScale||Starting Y size offset,|
|android:toXScale||Ending of X size offset|
|android:toYScale||Ending of Y size offset|
|android:fromDegrees||Starting angular position, in degrees.|
|android:toDegrees||Ending angular position, in degrees.|
|android:interpolator||An interpolator defines the rate of change of an animation|
At first, we will create a new android application. Then, we will create some animations.
If you already created the project then ignore step 1.
Create New Project
- Open Android Studio
- Go to File => New => New Project.
- Then, select Empty Activity and click on next
- Write application name as DynamicEditTextKotlin
- Select minimum SDK as you need, here we have selected 21 as minimum SDK
- Choose language as Kotlin and click on finish button.
If you have followed above process correctly, you will get a newly created project successfully.
After creating project we will modify xml files. In xml file we will create one TextView where all the animations are performed and Eight Buttons for Eight different animations.
Modify activity_main.xml file
Open res/layout/activity_main.xml file and add code into it.
After modifing the layout we will create xml files for animations. so we will first create a folder name anim.
In this folder, we will be adding the XML files which will be used to produce the animations. For this to happen, go to app/res right click and then select, Android Resource Directory and name it as anim.
In this animation the text is bounce like a ball.
In Fade In animation the text will appear from background.
In Fade Out animation the colour of text is faded for a particular amount of time.
In rotate animation the text is rotated for a particular amount of time.
In this animation the text will come from top to bottam.
In this animation the text will go from bottam to top.
In this animation the text will appear bigger for a particular amount of time.
In this animation the text will appear smaller for a particular amount of time.
After creating all animations in xml. we will create MainActivity.
Create MainActivity.kt file
Open app/src/main/java/net.geeksforgeeks.AnimationsInKotlin/MainActivity.kt file and add below code into it.
As, AndroidManifest.xml file is very important file in android application, so below is the code of manifest file.
Code inside src/main/AndroidManifest.xml file would look like below
Run as Emulator:
You can find the complete code here: https://github.com/missyadavmanisha/AnimationsInKotlin
- Android Toast in Kotlin
- Kotlin Android Tutorial
- Android TableLayout in Kotlin
- Android LinearLayout in Kotlin
- Android Fade In/Out in Kotlin
- Android RelativeLayout in Kotlin
- Android Slide Up/Down in Kotlin
- Android ListView in Kotlin
- Android FrameLayout in Kotlin
- Android EditText in Kotlin
- Android progress notifications in Kotlin
- How to create project in Android Studio using Kotlin
- AngularJS | Animations
- jQuery | Stop Animations
- Android Architecture
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.