我正面临一个问题,使用乐天文件作为动画。我不能设置循环号,而加载后,它是循环的,但我想设置固定的循环号码。
活动XML
<com.airbnb.lottie.LottieAnimationView
android:layout_centerInParent="true"
android:id="@+id/animation_view_1"
android:layout_width="150dp"
android:layout_height="150dp"
app:lottie_autoPlay="true"
app:lottie_loop="true" />活动Java
animationView.setVisibility(View.VISIBLE);
animationView.setAnimation(fileName);
animationView.loop(true);
animationView.playAnimation();发布于 2019-07-18 06:15:34
因为animationView.loop(true);被废弃了。除了之外,使用.xml文件
<com.airbnb.lottie.LottieAnimationView
...
app:lottie_repeatCount="3"
/>使用java您可以使用
animationView.setRepeatCount(LottieDrawable.INFINITE);// for Infinite loops或
animationView.setRepeatCount(3);// for 3 loops发布于 2019-07-18 05:58:26
试一试
<com.airbnb.lottie.LottieAnimationView
...
app:lottie_repeatCount="3"
/>发布于 2022-09-03 22:41:38
如果您使用jetpack,请撰写:
// Get lottie composition
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.idea_anim))iterations = 3,无限大使用iterations = LottieConstants.IterateForever// State of animation for composition
val progress by animateLottieCompositionAsState(
composition = composition,
iterations = LottieConstants.IterateForever
)LottieAnimation(
composition = composition,
progress = { progress }
)完整代码:
@Composable
fun AnyScreen() {
// Get lottie composition
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.idea_anim))
// State of animation for composition
val progress by animateLottieCompositionAsState(
composition = composition,
iterations = LottieConstants.IterateForever
)
LottieAnimation(
composition = composition,
progress = { progress }
)
}https://stackoverflow.com/questions/57087853
复制相似问题