Reputation: 21
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.
Upvotes: 1
Views: 2575
Reputation: 15025
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);
Upvotes: 0
Reputation: 77
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.
Upvotes: 2
Reputation: 600
the right answer is :
val animDrawable = LottieDrawable()
LottieCompositionFactory.fromRawRes(context, R.raw.loading_banner).addListener { comp ->
animDrawable.composition = comp
}
Upvotes: 1