繁体   English   中英

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

[英]how to replace Android image drawable (glide) with a lottie animation?

我想用包含 3 个状态的 1 个lotttie animation 替换这 3 个状态的 wifi 图像序列(连接、连接、连接):

  1. 当它空闲时,它应该显示来自wifi lottie animation的静止帧。
  2. 按下按钮时:从帧 x 到帧 y 播放wifi lottie animation
  3. 连接后,它会显示来自wifi lottie animation的静止帧。

这是我需要修改的 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.

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