android - 使用 Epoxy / DataBinding 设置为可见时,Android Lottie 动画不会自动启动
问题描述
我在带有 DataBinding 的 Android 项目中使用 Lottie 和 Epoxy。当 RecyclerView 被捕捉时,我想用 LottieImageView 开始动画,但是 LottieImageView 在设置为autoPlay=true
.
环氧树脂控制器如下:
class MainController : EpoxyController() {
var currentSnappedPosition = 0
set(value) {
field = value
requestModelBuild()
}
override fun buildModels() {
repeat(10) {
ItemBindingModel_()
.id(modelCountBuiltSoFar)
.isSnapped(currentSnappedPosition == modelCountBuiltSoFar)
.addTo(this)
}
}
}
currentSnappedPosition
当 RecyclerView 项目被捕捉时更新,然后rquestModelBuild()
被调用。
布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import
type="android.view.View" />
<variable
name="isSnapped"
type="boolean" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.airbnb.lottie.LottieAnimationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="@{isSnapped ? View.VISIBLE : View.GONE }"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/lunar_new_year"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:text="not snapped..."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="@{isSnapped ? View.GONE : View.VISIBLE }"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</FrameLayout>
</layout>
LottieAnimationView 设置为在项目被捕捉时可见。
整个项目在 GitHub 上:
有谁知道当 LottieAnimationView 设置可见时如何自动启动?
解决方案
推荐阅读
- android - 自定义字体在项目单击时重置系统默认值
- javascript - firestore firebase 问题:如何在不指定文档名称的情况下更新文档
- vue.js - vuetify 日期选择器范围限制为天数
- sequelize.js - 如何使用 sequelize 将查询实现为包含?
- python - 我有 5 个传感器:传感器同时读取环境
- python - 如何运行 QMovie 直到功能完成?
- javascript - 我正在尝试将 fs 读取的数据存储在变量中。但我得到未定义的输出?
- python-3.x - Matplotlib 内存不足
- node.js - NodeJS 上传文件
- go - 如何使用 png 图像生成带有 golang 的透明 GIF?