React Native Android 本地图片

6
我有这段代码:
<Image style={styles.image} source={require('image!logo')}/>

其中的logo.png被添加到了android/app/src/main/res文件夹中。
但是这个图片没有显示出来(我已经重新运行了react-native run-android)。
我需要进行其他改变吗?
请注意,使用<Image source={{uri: http://path/to/image}}/>可以成功显示图片。

https://facebook.github.io/react-native/docs/images.html#content - herbertD
2个回答

8

3
  1. After adding images you probably need to 'hard restart' the project. Just reloading the JS probably won't show the image.

  2. Since React Native 0.14, you can require images just like requiring JS files.

    <Image source={require('./img/check.png')} />
    
  3. Did you try to give your image some height?


非常感谢您在这里提供的第二条建议。文档中指出,图像的URI“可以是http地址、本地文件路径或静态图像资源的名称”,但他们给出的唯一带有路径的示例是http地址。我曾尝试使用source={{'./img/image.png'}},但无法弄清楚为什么我的图像不显示。 - flyingace
你最终解决了这个问题吗? - Saumil Shah

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接