我正在为所有国家创建一个滚动视图,每个国家都有一个标志作为图像和名称,我所基于的数据是从一个API中传递的,在API响应之后,我在state对象中设置国家数据,我调用它。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>
我在模拟器上测试了我的应用程序,它工作良好,但它不工作在我的真实设备上我得到的图像没有显示一个空的图像视图,请谁有任何想法可以帮助我,请分享它。 我有很多时间在寻找一个解决方案,但没有办法,请帮助。
您应该使用此命令构建应用程序。 react-native bundle--platform android--entry-file index.js--bundle-output android/app/src/main/assets/index.android.bundle--dev false--reset-cache-asset-dest android/app/src/main/res/
我还在我的应用程序中使用了URI作为Imagebackground,效果很好。 希望这能帮到你。