React native 用图像填充剩余空间

React native 用图像填充剩余空间,react-native,React Native,这是我的主视图,在视图的第二个子视图中有图像。我遇到的问题是,我希望视图组件中的图像填充剩余空间,但运气不佳。你知道我怎样才能做到吗?我尝试在高度和宽度上使用null,但它根本没有显示任何图像。resizeMode=“cover”也不起作用。flex属性适用于其他视图,但不适用于图像,我不知道为什么 <View style={{flex:1}}> <ProgressBar progress={0.3} width={width} color={"#ff0000"} /&

这是我的主视图,在视图的第二个子视图中有图像。我遇到的问题是,我希望视图组件中的图像填充剩余空间,但运气不佳。你知道我怎样才能做到吗?我尝试在高度和宽度上使用null,但它根本没有显示任何图像。resizeMode=“cover”也不起作用。flex属性适用于其他视图,但不适用于图像,我不知道为什么

<View style={{flex:1}}>
    <ProgressBar progress={0.3} width={width} color={"#ff0000"} />

    <View style={{flexDirection: 'row', marginTop: 10, alignItems: 'center', flex: 0.2}}>
      <Image style={styles.userImageStyle} source={{uri: item.item.userImage}} />
      <Text style={{marginLeft: 10}}>
        {item.item.username}
      </Text>
    </View>

    <View style={{flex: 0.8, marginTop: 20}}>
      <Image style={{width: null, height: null, flex:1}} resizeMode="cover" source={{uri: item.item.posts[0].imageUrl}} />
    </View>

  </View>

{item.item.username}

当您给flex 1时,宽度为“100%”,高度为空,然后图像将显示在剩余空间中

您可以使用此代码

<View style={{flex: 0.8, marginTop: 20}}>
   <Image style={{width: '100%', height: null, flex:1}} resizeMode="cover" source= 
 {{uri: item.item.posts[0].imageUrl}} />
</View>

使用未定义而不是空值。应该行得通



giving static{height:150 and width:150}(比方说)是否显示图像?是的。但我不知道我怎样才能用剩余的高度填满窗户的其余部分!