[我正在尝试在某些帧之间循环播放动画,但我根本看不到动画,如果我删除了LottieCompositionFactory....addListener
代码并仅使用xml文件,则会显示动画,但是,我想运行动画在某些帧之间:
class OnboardingFragment : Fragment() {
...
...
private var myComposition: LottieComposition? = null
...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
LottieCompositionFactory.fromRawRes(context, R.raw.my_animation)
.addListener {
myComposition = it
Log.d(TAG, "Is animation displaying: $myComposition") //does print the LottieComposition
with(lottieAnimation) {
alpha = 0F
visibility = View.VISIBLE
myComposition?.let { it1 -> setComposition(it1) }
repeatCount = ValueAnimator.INFINITE
setMinAndMaxFrame(29, 219)
playAnimation()
}
}
.addFailureListener {
Log.e(TAG, "Error displaying animation: ${it.message}")
}
和布局文件:
<androidx.constraintlayout.widget.ConstraintLayout
...
...
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottieAnimation"
android:layout_width="170dp"
android:layout_height="146dp"
android:layout_marginBottom="34dp"
android:scaleType="fitStart"
app:layout_constraintBottom_toTopOf="@+id/title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/topGuide"
app:lottie_autoPlay="true"
app:lottie_loop="true"/>
我尝试在上述布局中添加app:lottie_rawRes="@raw/my_animation"
,但没有任何改变。
所以,即使我不喜欢我同时使用android.animation.Animator
,android.animation.ValueAnimator
和LottieAnimation
,我还是采用了这种方法: