1

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.

TylerH
  • 20,799
  • 66
  • 75
  • 101
zluan
  • 21
  • 8

3 Answers3

1

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.

patrick.elmquist
  • 2,113
  • 2
  • 21
  • 35
Yash Singh
  • 57
  • 6
0

the right answer is :

val animDrawable = LottieDrawable()
LottieCompositionFactory.fromRawRes(context, R.raw.loading_banner).addListener { comp ->
    animDrawable.composition = comp
}
JeckOnly
  • 347
  • 2
  • 10
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 07 '21 at 08:44
0

Here is the code example:-

final private LottieDrawable ld = new LottieDrawable();
Field f = swipeRefreshLayout.getClass().getDeclaredField("mCircleView");
            f.setAccessible(true);
            ImageView imgVW = (ImageView)f.get(swipeRefreshLayout);
            ld.setBounds(0, 0, 64, 64);
            @SuppressLint("WrongThread") LottieResult<LottieComposition> result = LottieCompositionFactory.fromAssetSync(App.activity, "LottieSpinner.json");
            ld.setComposition(result.getValue());
            ld.setRepeatCount(LottieDrawable.INFINITE);
            imgVW.setImageDrawable(ld);
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56