简体   繁体   中英

React-Native FullScreen Backaground Image

So, l have been trying for about 4 days, but l just can't seem to get an image to behave like it should in flexbox , especially with the cover resizeMode.

My code is:

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'
  }
});

and outputs with the following (the image is massively stretched instead of being 100% width):

flexbox不起作用

Any help would be appreciated, just can't see why its not working!

resizeMode is a separate prop for the Image component, it has no effect inside the style prop. It also expects an enum from the Image component. So you should be using it like so:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM