Android Animation: Fade Out (Kotlin)

Jun 19, 2019

Solution 1: AnimationSet

val fadeOut = AlphaAnimation(1f, 0f)fadeOut.interpolator = AccelerateInterpolator()fadeOut.duration = 1000val animation = AnimationSet(false)/*animation.setAnimationListener(object: Animation.AnimationListener {    override fun onAnimationRepeat(animation: Animation?) {    }    override fun onAnimationEnd(animation: Animation?) {        view.isVisible = false    }    override fun onAnimationStart(animation: Animation?) {    }}) */animation.addAnimation(fadeOut)view.startAnimation(animation)view.isVisible = false

Solution 2: XML

Create res/anim/fade_out.xml.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android=""
    <alpha android:fromAlpha="1.0"
view.startAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_out))view.isVisible = false

Solution 3: ObjectAnimator

ObjectAnimator.ofFloat(view, View.ALPHA, 1f, 0f).setDuration(1000).start()


val animator = ObjectAnimator.ofFloat(view, View.ALPHA, 1f, 0f)animator.interpolator = AccelerateInterpolator()animator.duration = 1000animator.start()

Soltion 4: animate


❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.