BindingAdapter to load Custom Animatoin

53 Views Asked by At

I simply want to achieve any of the below

app:CustomAnimationtoLoad="@anim/slide_top_to_bottom"
or 
app:CustomAnimationtoLoad="R.anim.slide_top_to_bottom"
or
app:CustomAnimationtoLoad="@{R.anim.slide_top_to_bottom}"

I have tried below code.

@BindingAdapter("CustomAnimationtoLoad")
fun View.CustomAnimationtoLoad(@AnimRes int: Int){
    val bounce = AnimationUtils.loadAnimation(
        context, int//R.anim.bounce_animation
    )
    startAnimation(bounce)
}

Not able to achieve.

1

There are 1 best solutions below

1
grimface On

Shouldnt it be like that?

@BindingAdapter("CustomAnimationtoLoad")
fun View.customAnimationtoLoad(@AnimRes int: Int){
    val bounce = AnimationUtils.loadAnimation(
        context, int//R.anim.bounce_animation
    )
    startAnimation(bounce)
}

Does your version even compile?