如何在 react-native 中使用 ImageBackground 为屏幕设置背景图片

新手上路,请多包涵

当我在 react-native 中使用时,它会发出警告,指出不推荐使用与孩子一起使用,将来会出错。用户代替。

所以,如果我使用它不会给出我正在使用的预期结果

这是我为使用而编写的代码

<ImageBackground source={require('../../img/splash/splash_bg.png')} style={styles.backgroundImage} >
        </ImageBackground>

样式代码是

const styles = StyleSheet.create({
backgroundImage: {
    flex: 1,
    // width: undefined,
    // height: undefined,
    // flexDirection: 'column',
    // backgroundColor:'transparent',
    // justifyContent: 'flex-start',

},}

预期结果:使用 <Image> 时得到结果使用 <ImageBackground>

原文由 Waqas 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 544
1 个回答

您可以在 React Native 上使用 “ImageBackground” 组件。

 <ImageBackground
  source={yourSourceFile}
  style={{width: '100%', height: '100%'}}
>
    <....yourContent...>
</ImageBackground>

原文由 Tiago Gouvêa 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏