在React Native中将图像垂直锚定到其顶部

Gui*_*ume 7 react-native

我有一些代码可以将随机大小的图像扩展到容器的整个宽度+在容器内部垂直居中。但是我需要将其锚定在顶部。

在CSS中,我会使用背景位置,但是React Native不支持它。我觉得我已经尝试过resizeMode,绝对定位等的每种组合-但仍然无法弄清楚。

<View style={{
  flex: 1,
  height: 120,
}}>
  <Image source={{uri: source}} style={{
    flex: 1,
    width: '100%',
    resizeMode: 'cover'
  }}>
  </Image>
</View>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

Sye*_*Ali -1

在此输入图像描述

  return (
          <View
            style={{
              flex: 1,
              height: 120,
              justifyContent: "center",
              alignContent: "center"
            }}
          >
            <TouchableOpacity onPress={() => alert("Hello ")}>
              <Text style={{ alignSelf: "center" }}>Anchor Tag</Text>
            </TouchableOpacity>
            <Image
              source={{
                uri: "https://shoutem.github.io/img/ui-toolkit/examples/image-3.png"
              }}
              style={{
                width: "100%",
                height: 100,
                resizeMode: "cover"
              }}
            />
          </View>
Run Code Online (Sandbox Code Playgroud)

  • 谢谢!但这其实不是我想要的结果。图像的可见部分是它的垂直中心,但我想要垂直顶部,也就是天空的部分 (3认同)