[英]how to replace Android image drawable (glide) with a lottie animation?
i wanted to replace these 3 states wifi images sequence(connect,connecting,connected) with 1 lotttie animation containing the 3 states:我想用包含 3 个状态的 1 个lotttie animation 替换这 3 个状态的 wifi 图像序列(连接、连接、连接):
this is the java code i need to modify:这是我需要修改的 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);
}
}
Replace you ImageView
with this用这个替换你
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"/>
in xml file.在 xml 文件中。 Replace your activity glide code with the below code and give your json file according to your if condition.
将您的活动滑行代码替换为以下代码,并根据您的 if 条件提供您的 json 文件。
animationView.setAnimation("abc.json")
animationView.playAnimation()
animationView.loop(true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.