• Lottie动画多动图切换遇到的坑


    问题原因是多动图json文件切换动图效果变成静态图。

    布局:

    Dialog:

    public class PermissionLoadingDialog extends Dialog implements DialogInterface.OnDismissListener {
    
        private Context mContext;
        private LottieAnimationView lottieView;
        private TextView tvId;
        private String json = "";
    
        public PermissionLoadingDialog(@NonNull Context context, int themeResId) {
            super(context, themeResId);
            this.mContext = context;
        }
    
        public static boolean isMobileConnected(Context context) {
            if (context != null) {
                ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                        .getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo mMobileNetworkInfo = mConnectivityManager
                        .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
                if (mMobileNetworkInfo != null) {
                    return mMobileNetworkInfo.isAvailable();
                }
            }
            return false;
        }
    
        public void test(String id) {
            if (isMobileConnected(mContext)) {
                tvId.setText(id + "/5");
            } else {
                tvId.setText(id + "/4");
            }
            if (lottieView.isAnimating()) {
                lottieView.cancelAnimation();
            }
            if (id.equals("1")) {
                json = "wifi.json";
            }
            if (id.equals("2")) {
                if (isMobileConnected(mContext)) {
                    json = "cellular_network.json";
                } else {
                    json = "bluetooth.json";
                }
            }
            if (id.equals("3")) {
                if (isMobileConnected(mContext)) {
                    json = "bluetooth.json";
                } else {
                    json = "gps.json";
                }
            }
            if (id.equals("4")) {
                if (isMobileConnected(mContext)) {
                    json = "gps.json";
                } else {
                    json = "battery.json";
                }
            }
            if (isMobileConnected(mContext)) {
                if (id.equals("5")) {
                    json = "battery.json";
                }
            }
            LottieComposition.Factory.fromAssetFileName(mContext, json, composition -> {
                lottieView.setComposition(composition);
                lottieView.setAnimation(json);
                lottieView.playAnimation();
            });
        }
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            getWindow().setDimAmount(0.2f);
            View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_permission_loading_anim, null);
            setContentView(inflate);
            lottieView = inflate.findViewById(R.id.lottieAnimView);
            tvId = inflate.findViewById(R.id.tv_id);
            setOnDismissListener(this);
            this.setCanceledOnTouchOutside(false);
            this.setCancelable(false);
        }
    
        @Override
        public void show() {
            super.show();
            lottieView.playAnimation();
        }
    
        @Override
        public void onDismiss(DialogInterface dialog) {
            if (lottieView != null) {
                lottieView.pauseAnimation();
            }
        }
    
        public static PermissionLoadingDialog showDiaolog(Context context) {
            PermissionLoadingDialog loadingDialog = new PermissionLoadingDialog(context, R.style.AwakenDialog);
            loadingDialog.show();
            return loadingDialog;
        }
    }
    
    
                    
  • 相关阅读:
    【Vue】模块基本语法「上篇」
    k8s 集群安装(vagrant + virtualbox + CentOS8)
    企业为什么要选择通配符SSL证书使用?
    vulnhub靶机Presidential
    【华为机试真题 JAVA】数列描述-100
    LeetCode - 反转链表Ⅱ
    【无标题】
    你了解机械键盘吗?Keychron Q1开箱与体验实录
    算法设计与分析-0/1背包问题
    嵌入式分享合集63
  • 原文地址:https://blog.csdn.net/xige1995/article/details/127430105