简体   繁体   English

如何用lottie animation 替换 Android 图像可绘制(滑动)?

[英]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 图像序列(连接、连接、连接):

  1. When its idle it should display a still frame from wifi lottie animation .当它空闲时,它应该显示来自wifi lottie animation的静止帧。
  2. When button is pressed : plays wifi lottie animation from frame x to frame y.按下按钮时:从帧 x 到帧 y 播放wifi lottie animation
  3. When connected it displays a still frame from wifi lottie animation .连接后,它会显示来自wifi lottie animation的静止帧。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM