React-Native:图片resizeMode无法正常工作

时间:2018-09-13 03:32:16

标签: react-native

尝试在resizeMode: 'cover'组件中设置Image时遇到问题

此图片总结了我的问题:

enter image description here

我正在 Android RN 0.55.3 和我的示例代码上进行测试

<View style={{ width: 200, height: 200, backgroundColor: '#555' }}>
  <Image
    source={require('./bird.jpg')}
    style={{ alignSelf: 'stretch', flex: 1, resizeMode: 'cover' }}
  />
</View>

也尝试过:

<View style={{ width: 200, height: 200, backgroundColor: '#555' }}>
      <Image
        source={require('./bird.jpg')}
        style={{ alignSelf: 'stretch', flex: 1 }}
        resizeMode='cover'
      />
</View>

但是两者都不起作用,那么有什么方法可以使其正常工作?

2 个答案:

答案 0 :(得分:1)

我发现resizeMode不能正常工作,除非我设置width的{​​{1}}

我使用了Image,并且一切正常

最终代码:

width: 'auto'

答案 1 :(得分:0)

我如下定义Image标签。样式之外的resizeMode。

 <View style={{ width: 200, height: 200, backgroundColor: '#555' }}>
      <Image
        source={require('./bird.jpg')}
        style={{ alignSelf: 'stretch', flex: 1,width : 'auto'}}
        resizeMode={'cover'}
      />
 </View>

这对我有用。

相关问题