如何在 React Native 中拉伸静态图像作为背景?

2024-03-03

我想在我的 React Native 应用程序中使用背景图像, 图像比屏幕小,所以我必须拉伸它。

但如果图像是这样,它就不起作用从资源包加载

var styles = StyleSheet.create({
  bgImage: {
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'stretch',
    resizeMode: 'stretch',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  }
});

<Image source={require('image!background')} style={styles.bgImage}>
  <Text style={styles.welcome}>
    Welcome to React Native!
  </Text>
</Image>

它看起来像这样:

但是,它对于远程图像效果很好,通过source={{uri: 'background-image-uri'}}:


来自 Github 问题:图像 {require} 在 React Native 中因调整大小而损坏 https://github.com/facebook/react-native/issues/4598#issuecomment-162328501,你可以尝试<Image style={{width: null, height: null}},希望facebook尽快修复。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 React Native 中拉伸静态图像作为背景? 的相关文章

随机推荐