【发布时间】:2020-12-18 01:04:29
【问题描述】:
我正在使用从react-native 导入的 ImageBackground 组件,但没有显示图像。只是背景中的白屏
constructor(props){
super(props)
this.backgroundImage = {image: {uri: "https://i.myImage.com"}}
}
......
<ImageBackground style={styles.container} resizeMode="stretch" source={this.backgroundImage} onError={this.onError.bind(this)}>
<AdUnit style={styles.bannerAd} />
<Board />
</ImageBackground>
我尝试将this.backgroundImage 更改为{image: require('../assets/images/default_seal.jpg')}
我尝试使用 resizeMode 属性 specified by this answer,但没有成功。
【问题讨论】:
-
这段代码在哪个文件中?在你的 Github 存储库中?
-
@MarcusMelodious
components/soundboard.js抱歉 -
尝试直接在 ImageBackground 组件中设置: source={require('../assets/images/default_seal.jpg')} 并查看它是否显示图像。认为问题出在第 222 行: this.backgroundImage = {image:{uri: images[Math.floor(Math.random() * 16)]}} 不确定为什么在构造函数中有这样的内容。看起来您正在将数组而不是字符串传递给 uri。
-
其实我只是在你的组件中看到了图片文件。如果您要传递图片网址。您必须像这样设置它:source={{ uri: this.backgroundImage }}。
标签: javascript reactjs react-native imagebackground