javascript - React Native 背景图片只是一个白屏
问题描述
我正在使用从 导入的 ImageBackground 组件,react-native
但没有显示图像。只是背景中的白屏
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 属性,但它不起作用。
解决方案
<ImageBackground
source={yourSourceFile}
style={{width: '100%', height: '100%'}}
>
<....yourContent...>
</ImageBackground>
如果您自己渲染图像属性,它绝对正确吗?例如
{this.backgroundImage}
在 chrome 中是在网络选项卡中加载的图像,或显示错误
页面上有css吗?如果是这样,您可以将其删除并重新测试。另一种选择:
<ImageBackground style={ styles.imgBackground }
resizeMode='cover'
source={require('./Your/Path.png')}>
</ImageBackground>
样式:
imgBackground: {
width: '100%',
height: '100%',
flex: 1
},
推荐阅读
- python - Pandas 不适用于 Spark 并行代码
- kubernetes - 使用 helm 安装 kubernetes-dashboard 失败
- c# - 如何在 c# 中将 DateTime.Now 转换为 0 到 1 十进制格式
- .net - 使用 WPF ElementHost 托管的 WPF 控件仅在 Win 7 下存在鼠标滚轮问题
- ms-access - 如何从“子表单”中选择的表中删除特定记录?
- javafx - 按下 F4 时禁用 ComboBox 下拉菜单
- c++ - 为什么我们需要创建一个单参数构造函数才能使用临时无名对象?
- javascript - 将列矩阵中的所有零移到末尾
- javascript - 如何在 TypeScript 中链接函数参数类型?
- android - 离子 HTML 输入没有为 android 上的图像提供相机选择