首页 > 解决方案 > 为什么我的反应原生项目中没有应用背景图像

问题描述

应用程序内文件夹,我有两个文件夹屏幕和资产,我提供了正确的路径,但背景图像未应用于模拟器。

在此处输入图像描述

标签: cssreact-native

解决方案


用 View 包裹你的 imageBackground:

    <View style={styles.imgWrap}>
      <ImageBackground 
        source={require('assets/img/avatar-placeholder.png')} 
        style={styles.img} 
      />
    </View>

然后添加一些样式:

 const styles = StyleSheet.create({
  imgWrap: {
    width: 100,
    height: 100,
    overflow: 'hidden',
    borderRadius: 50,
  },
  img: {
    flex: 1,
    resizeMode: "contain",
    justifyContent: "center"
  }
})

推荐阅读