【发布时间】:2020-07-03 14:50:16
【问题描述】:
我正在为所有国家/地区创建滚动视图,每个国家/地区都有一个标志作为图像和名称,我基于的数据来自 API,在 API 响应后我设置国家数据在状态对象中,我调用 this.setSatet(newstate) 来更新滚动视图。
所以,我正在使用此代码显示每个国家/地区的国旗:
{
this.state.data_countries.map((country, index) => (
<View key={country._id} style={styles.item}>
<Image
source={{
uri: country.countryInfo.flag,
}}
style={{
maxWidth: 40,
maxHeight: 30,
flex: 1,
}}
onError={this.test_error}
></Image>
<Text
style={{
textAlign: "center",
flex: 1,
}}
>
{country.country}
</Text>
</View>
));
}
我确保给出的 URI 是正确的,我已将以下所有网络安全添加到我的 android 项目中:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<!-- THIS FOR THE DOMAIN OF MY IMAGES SOURCE example : https://disease.sh/assets/img/flags/us.png-->
<domain includeSubdomains="true">disease.sh</domain>
<!-- THIS FOR THE DOMAIN OF MY API -->
<domain includeSubdomains="true">nepalcorona.info</domain>
</domain-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
我在模拟器上测试了我的应用程序,它运行良好,但在我的真实设备上无法运行我得到的图像没有显示一个空的图像视图,请有任何想法的人可以帮助我,请分享。我花了很多时间寻找解决方案,但没有办法,请帮忙。
【问题讨论】:
标签: javascript android reactjs react-native react-native-image