[英]how to replace Android image drawable (glide) with a lottie animation?
我想用包含 3 個狀態的 1 個lotttie animation 替換這 3 個狀態的 wifi 圖像序列(連接、連接、連接):
這是我需要修改的 java 代碼:
protected void loadIcon() {
if (state == WifiState.IDLE) {
Glide.with(this).load(R.drawable.ic_connect).into(connectButtonTextView);
Glide.with(this).load(R.drawable.ic_connect).into(connectButtonTextView);
} else if (state == WifiState.CONNECTING_WIFI || state == WifiState.CONNECTING_CREDENTIALS) {
connectButtonTextView.setVisibility(View.VISIBLE);
Glide.with(this).load(R.drawable.is_connecting).into(connectButtonTextView);
} else if (state == WifiState.CONNECTED) {
Glide.with(this).load(R.drawable.ic_connected).into(connectButtonTextView);
Glide.with(this).load(R.drawable.ic_connected).into(connectButtonTextView);
connectButtonTextView.setVisibility(View.VISIBLE);
}
}
用這個替換你ImageView
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:lottie_url="REPLACE_JSON_URL"
app:lottie_autoPlay="true"
app:lottie_loop="true"/>
在 xml 文件中。 將您的活動滑行代碼替換為以下代碼,並根據您的 if 條件提供您的 json 文件。
animationView.setAnimation("abc.json")
animationView.playAnimation()
animationView.loop(true)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.