代码之家  ›  专栏  ›  技术社区  ›  Mujtaba Fadhil

React Native:图像大小调整模式工作不正常

  •  0
  • Mujtaba Fadhil  · 技术社区  · 6 年前

    我在尝试设置时遇到了问题 resizeMode: 'cover' 在里面 Image 成分

    enter image description here

    我正在测试 ,

    <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 回复  |  直到 6 年前
        1
  •  5
  •   Mujtaba Fadhil    6 年前

    我发现了 resizeMode width Image

    我曾经 width: 'auto' 一切都很顺利

    最终代码:

    <View style={{ width: 200, height: 200, backgroundColor: '#555' }}>
      <Image
        source={require('./bird.jpg')}
        style={{ alignSelf: 'stretch', flex: 1, resizeMode: 'cover', width: 'auto' }}
      />
    </View>
    
        2
  •  0
  •   Iva Nikhil Dangi    5 年前

    我定义图像标签如下。样式外的resizeMode。

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