Skip to content

Instantly share code, notes, and snippets.

@jesselima
Created February 18, 2021 16:18
Show Gist options
  • Save jesselima/0d6ae6396d9dca70e409a385750be713 to your computer and use it in GitHub Desktop.
Save jesselima/0d6ae6396d9dca70e409a385750be713 to your computer and use it in GitHub Desktop.
Sample extension to show fadein with animation
package tech.jesselima.statistics.extensions
import android.animation.ObjectAnimator
import android.view.View
import android.view.animation.AnimationUtils
import tech.jesselima.commonextensions.R
fun View.showWithAnimatedFadeIn(
translationType: TranslationType = TranslationType.TRANSLATION_Y,
animDuration: AnimDuration = AnimDuration.TIME_1000_MS
) {
this.visibility = View.VISIBLE
ObjectAnimator.ofFloat(
this,
translationType.value,
-50f
).apply {
duration = animDuration.value
start()
}
this.startAnimation(
AnimationUtils.loadAnimation(context,
R.anim.fade_in_animation_1000ms
))
}
enum class TranslationType(val value: String) {
TRANSLATION_Y("translationY"),
TRANSLATION_X("translationX")
}
enum class AnimDuration(val value: Long) {
TIME_500_MS(500L),
TIME_1000_MS(1000L),
TIME_2000_MS(2000L),
TIME_3000_MS(3000L),
TIME_4000_MS(3000L),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment