将图像大小调整为视图 - 反应原生

smu*_*uvv 3 css android resize reactjs react-native

我想知道是否可以调整图像大小以使其适合视图。

这就是我现在所拥有的

 <View style={styles.container}>
    <View style={styles.header}>
      <Image
        source={headerImage}    
      />

    </View>
    <Text style={styles.basicText}>text</Text>
  </View>
Run Code Online (Sandbox Code Playgroud)
 const styles = StyleSheet.create({
      container: {
        flex: 1,
        backgroundColor: "#fff"
      },
      header: {
        height: 200, 
        backgroundColor: 'red'
      },
      background: {
        width: null,
        height: null
      },
      image: {

      }
Run Code Online (Sandbox Code Playgroud)

我想让图像适合标题视图。

Ant*_*amp 7

添加到 Moti Azu 的答案中,您还需要设置 resizeMode。

image: {
  flex:1,
  height: null,
  resizeMode: 'contain',
  width: null,
}
Run Code Online (Sandbox Code Playgroud)

如果它似乎不起作用,请确保您的Viewwith 样式container具有宽度。