react-native - 反应原生图像不显示在android模拟器上
问题描述
下面是我的代码
<View style={{ flex: 1, backgroundColor: "#f1f5f7", alignItems: "center" }}>
<ScrollView>
<ImageBackground
source={{
uri:
"https://mosfeed.id/assets/collections/ads/small/photo_2021-03-10%2016.38.26.jpeg",
}}
style={{
width: screenWidth,
height: 190,
alignItems: "center",
justifyContent: "center",
paddingHorizontal: 50,
}}
></ImageBackground>
<ItemData title="Upcoming Events" data={DATA1} />
<ItemData title="Premium" data={DATA2} />
</ScrollView>
<MaterialSnackbar ref={snackbarRef} />
</View>
问题是图像仅显示在 android 模拟器上且仅来自我的服务器。但是当我从其他服务器链接更改链接时,图像显示。
是否有任何设置可以在我的服务器上显示图像。
谢谢
解决方案
我通过以下方式实现了这一目标:
import { ImageBackground } from 'react-native';
<ImageBackground style={ styles.imgBackground }
resizeMode='cover'
source={require('./Your/Path.png')}>
//place your now nested component JSX code here
</ImageBackground>
然后是样式:
imgBackground: {
width: '100%',
height: '100%',
flex: 1
},
推荐阅读
- docker - 使用 docker-compose 将 Elasticsearch 请求/查询记录到 docker 实例的标准输出
- php - 通过 phpseclib 上传的文件减少到 14 个字节?
- cratedb - Cratedb 自定义排序
- workflow - 使用堆栈跟踪和消息终止工作流
- javascript - 无法重置只读输入文本
- reactjs - 使占位符加载响应
- python - 如何使函数的返回值不在括号中?
- python - 如何将边缘列表读入networkx中的图形?
- drools - Drools Kie Builder - 无法构建 MavenEmbedder 错误
- python - Sklearn 错误:R^2 分数在少于两个样本的情况下定义不明确