Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to define a LottieDrawable?

It looks like LottieComposition.Factory is deprecated already. I'm wondering how I can define a LottieDrawable? I could not find the documentation for this.

The reason I want a Drawable is because I want to pass a Lottie animation into fresco as a placeholder drawable.

like image 408
zluan Avatar asked Dec 21 '25 09:12

zluan


2 Answers

I realise this is an old question, but since I too came against the same problem and managed to find how to do it, might as well share it.

So a LottieCompositionFactory can be used to obtain a LottieComposition from a raw .json file, URL, or assets in the assets folder etc. using the corresponding function as given in the API reference, and then use the composition to assign it to a LottieDrawable.

For example, using a .json file

val animDrawable = LottieDrawable()
LottieCompositionFactory.fromRawRes(requireContext(), R.raw.anim_file).addListener {comp ->
    animDrawable.composition = comp
}

Then the drawable can be used anywhere a Drawable can be passed.

like image 119
Yash Singh Avatar answered Dec 23 '25 23:12

Yash Singh


the right answer is :

val animDrawable = LottieDrawable()
LottieCompositionFactory.fromRawRes(context, R.raw.loading_banner).addListener { comp ->
    animDrawable.composition = comp
}
like image 26
JeckOnly Avatar answered Dec 23 '25 22:12

JeckOnly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!