【问题标题】:React-Native FullScreen Backaground ImageReact-Native 全屏背景图片
【发布时间】:2015-08-26 21:27:05
【问题描述】:

所以,我已经尝试了大约 4 天,但我似乎无法让图像在flexbox 中表现得像应有的那样,尤其是使用cover resizeMode。

我的代码是:

var Creator = React.createClass({
  render: function() {
  return (
    <View style={ styles.container }>
      <Image source={ require('image!createBg') } style={ styles.image }></Image>
    </View>
  );
 }
});

var styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  image: {
    flex: 1,
    resizeMode: 'cover'
  }
});

并输出以下内容(图像被大量拉伸而不是 100% 宽度):

任何帮助将不胜感激,只是不明白为什么它不起作用!

【问题讨论】:

标签: javascript ios css iphone react-native


【解决方案1】:

resizeMode 是 Image 组件的一个单独的 prop,它在 style prop 内部没有任何作用。它还需要来自 Image 组件的枚举。所以你应该像这样使用它:

<Image
 source={require('image!createBg')}
 style={styles.image}
 resizeMode={Image.resizeMode.contain} />

【讨论】:

  • 干杯老兄。还需要将alignItems: 'center'添加到容器中才能使其完全工作
  • 是的,很高兴听到它对您有用。似乎与boredgames相关的问题的答案已过时。考虑到 React Native API 的变化速度之快,这并不奇怪。
猜你喜欢
  • 1970-01-01
  • 2021-01-20
  • 2020-12-18
  • 2021-09-29
  • 2017-10-07
  • 2019-12-30
  • 2012-06-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多