响应本机绝对定位使图像裁剪

时间:2020-11-11 11:16:23

标签: react-native stylesheet

我在将图像放置在容器中时遇到问题,就是当我给图像position: absolutetop属性图像从顶部裁剪时,这是问题所在:

enter image description here

这是我的代码:

<View style={styles.OurTherapistsContainer}>
          <View style={styles.therapistCard}>
            <View style={styles.imageContainer}>
            <Image style={styles.image} source={require('../assets/img/leong.png')} />
            </View>
          </View>
      </View>

...
therapistCard: {
    width: 150,
    height: 150,
    borderRadius: 25,
    borderWidth: 1,
    borderColor: '#DFEEFF',
    overflow: 'hidden',
  },
  imageContainer: {
    width: 150,
    height: 150,
    backgroundColor: 'red',
  },
  image: {
    width: '100%',
    height: '100%',
    position: "absolute",
    top: 30
  }

我该如何解决?

2 个答案:

答案 0 :(得分:0)

尝试以类似图像的样式使用resizeMode

resizeMode:'contain'

答案 1 :(得分:0)

将resizeMode设置为 cover

<Image style={styles.image} resizeMode="cover" source {require('../assets/img/leong.png')} />