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="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="1000"
android:interpolator="@android:anim/accelerate_interpolator"
/>
</set>
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()
or
val animator = ObjectAnimator.ofFloat(view, View.ALPHA, 1f, 0f)animator.interpolator = AccelerateInterpolator()animator.duration = 1000animator.start()
Soltion 4: animate
view.animate().alpha(0f).setDuration(1000).setInterpolator(AccelerateInterpolator()).start()