gpt4 book ai didi

android - 无法从 URL 加载 Lottie 动画

转载 作者:行者123 更新时间:2023-12-03 08:02:14 25 4
gpt4 key购买 nike

我正在尝试从 URL 在我的 View 中添加 Lottie 动画。我可以从本地资源文件夹加载。但是当我尝试从 url 加载时,它没有显示。请帮我解决这个问题。

这是我的代码:

        String cacheKey ="LOTTIE_CACHE_KEY";
mLottieDrawable = new LottieDrawable();
mLottieDrawable.enableMergePathsForKitKatAndAbove(true);
mLottieDrawable.setCallback(this);
/*LottieResult<LottieComposition> result =
LottieCompositionFactory.fromAssetSync(getContext().getApplicationContext(),
"woman_singer.json");
mLottieDrawable.setComposition(result.getValue());*/

String url = "https://assets5.lottiefiles.com/packages/lf20_GoeyCV7pi2.json";
mLottieDrawable.setComposition(LottieCompositionFactory.fromUrlSync(getContext(), url, cacheKey).getValue());
mLottieDrawable.setRepeatCount(LottieDrawable.INFINITE);

mLottieDrawable.addAnimatorUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
invalidate();
}
});
mLottieDrawable.start();

最佳答案

忘记在我的 AndroidManifest 中添加互联网权限。而且这段代码对于从事 Lottie 工作的人也很有用。我在很多网站上进行了搜索。没有使用 LottieDrawable 的正确示例。因此任何人都会从这段代码中受益。

String cacheKey ="LOTTIE_CACHE_KEY";
mLottieDrawable = new LottieDrawable();
mLottieDrawable.enableMergePathsForKitKatAndAbove(true);
mLottieDrawable.setCallback(this);
/*LottieResult<LottieComposition> result =
LottieCompositionFactory.fromAssetSync(getContext().getApplicationContext(),
"woman_singer.json");
mLottieDrawable.setComposition(result.getValue());*/

String url = "https://assets5.lottiefiles.com/packages/lf20_GoeyCV7pi2.json";
mLottieDrawable.setComposition(LottieCompositionFactory.fromUrlSync(getContext(), url, cacheKey).getValue());
mLottieDrawable.setRepeatCount(LottieDrawable.INFINITE);

mLottieDrawable.addAnimatorUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
invalidate();
}
});
mLottieDrawable.start();

关于android - 无法从 URL 加载 Lottie 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73657802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com