【问题标题】:React Native cant set image as backgroundReact Native 无法将图像设置为背景
【发布时间】:2018-04-22 15:31:21
【问题描述】:

我一直在尝试将图像设置为 react 本机应用程序的背景,但没有成功。

这是我的图片标签。

<Image
source={require('../img/cat.jpg')}
style={styles.backgroundImage}
blurRadius={1} />

它应该包含子元素,应该呈现在顶部。

样式如下:

backgroundImage: {
    flex: 1,
    width: null,
    height: null,
    resizeMode: 'cover',
  },

目前,子元素呈现在屏幕底部,在图像之后,而不是在其顶部。

我应该如何做到这一点?

【问题讨论】:

标签: image react-native background render


【解决方案1】:

RN 现在提供&lt;ImageBackground&gt; 组件作为described in the docs 并用作

 return (
  <ImageBackground source={...}>
    <Text>Inside</Text>
  </ImageBackground>
 );

或者,您可以使用position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, resizeMode: 'stretch'//or 'contain' 与您的图像样式。

【讨论】:

    猜你喜欢
    • 2021-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多