• 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;
        }
    }
    
    
                    
  • 相关阅读:
    【Python】基本数据类型(二)数字类型的运算符
    Python顺序结构程序设计(湖南工业大学)
    nginx基础架构
    测试一波回归模型的误差
    视错觉与魔术(一)——经典回顾
    halcon如何识别硬币?
    dpdk hw-offload flows i
    操作系统——虚拟内存
    【C++】使用VS2022和GCC编译Xlnt库读取EXCEL
    需求是怎么一步一步变态的
  • 原文地址:https://blog.csdn.net/xige1995/article/details/127430105