This my extension, this is an example of change image with FadIn and FadOut :
fun ImageView.setImageDrawableWithAnimation(@DrawableRes() resId: Int, duration: Long = 300) {
if (drawable != null) {
animate()
.alpha(0f)
.setDuration(duration)
.withEndAction {
setImageResource(resId)
animate()
.alpha(1f)
.setDuration(duration)
}
} else if (drawable == null) {
setAlpha(0f)
setImageResource(resId)
animate()
.alpha(1f)
.setDuration(duration)
}
}