Kotlin Transition Animation (KTA)

Hey, making Fade In/Out animation on Android is really easy, bro/sis! So, we can use XML for the animation.


1. Fade In:

Create the file res/anim/fade_in.xml:

Here is a collection of android transition animations declared inside xml files.

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="1000" />


Then in the Kotlin code:

val fadeIn: Animation = AnimationUtils.loadAnimation(applicationContext, R.anim.fade_in)
yourView.startAnimation(fadeIn)


2. Fade Out:

Create the file res/anim/fade_out.xml:

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:fromAlpha="1.0"
    android:toAlpha="0.0"
    android:duration="1000" />


Then in the Kotlin code:

val fadeOut: Animation = AnimationUtils.loadAnimation(applicationContext, R.anim.fade_out)
yourView.startAnimation(fadeOut)


It's the same as Java. Only the Kotlin code is a little more relaxed. Hope this helps, bro/sis! 🚀😊


explode.xml

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">

    <explode
        android:duration="1000"
        android:interpolator="@android:interpolator/accelerate_cubic"/>

</transitionSet>


fade.xml

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
    <fade android:duration="1000"/>
</transitionSet>


slide.xml

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
    <slide
        android:duration="1000"
        android:slideEdge="bottom"/>
</transitionSet>

Source

https://gist.github.com/KarthikKumarBA/851e129c31ea4605a5cd02aa99da5aab


Post a Comment

Previous Next

نموذج الاتصال