gpt4 book ai didi

android - 如何在 Android 端动画加载 GIF?

转载 作者:行者123 更新时间:2023-11-30 05:01:33 28 4
gpt4 key购买 nike

我的 React Native 项目中有这个 GIF:

import React from "react";
import { View, StyleSheet, Image } from "react-native";
import PropTypes from "prop-types";

const Loading = () => (
<View style={styles.container}>
<Image source={require("./Loading.gif")} style={styles.containerLoader} />
</View>
);

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
color: "#00AD50"
},
containerLoader: {
width: 150,
height: 150
}
});

export { Loading };

它是三个脉动点,在 iOS 端工作得很好,但在 Android 端什么都不做。我看过一些相关的帖子:

所以这个显然太老了: Animated gif in android

但是这里谈到需要将图像分解成帧: How to animate .gif images in an android?

以上内容今天仍然适用吗?如果是这样,是否有关于如何完成的文档?

如果没有,那我怎么才能让上面的 GIF 文件动起来呢?

我试图实现一位同事通过此文档提供的内容: https://facebook.github.io/react-native/docs/image#gif-and-webp-support-on-android

所以在我的 android/app/build.gradle 中:

   dependencies {
implementation 'com.facebook.fresco:animated-gif:1.12.0'
implementation project(':react-native-device-info')
implementation project(':react-native-onesignal')
implementation project(':react-native-immediate-phone-call')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From
node_modules

if (enableHermes) {
def hermesPath = "../../node_modules/hermesvm/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}

但上面的代码没有对 GIF 进行动画处理。所以虽然它是 referenced here as a solution ,那对我不起作用。

最佳答案

同时检查 this post如果您使用的是 react-native 0.60+。

简而言之,引用正确的 fresco 版本很重要:

// For animated GIF support
implementation 'com.facebook.fresco:fresco:2.0.0'
implementation 'com.facebook.fresco:animated-gif:2.0.0'

关于android - 如何在 Android 端动画加载 GIF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58169886/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com