1

我正在尝试定位一个类似于您使用网络的 backgroundPosition: top 的图像。意思是,如果图像的尺寸大于我应用于图像的样式的高度和宽度,那么它将确保显示的图像部分从顶部开始。

我试图在 React Native 中做到这一点,但没有运气弄清楚。其他 StackOverflow 问题指向绝对定位 ImageBackground,但我没有任何运气。

到目前为止,这是我正在使用的内容:

<ImageBackground
    // resizeMethod={'contain'}
    source={{ uri: item.image }}
    style={{
        width: "100%",
        height: 120,
        backgroundColor:'#000',
        padding: 20,
        paddingVertical: 40,
        position: 'absolute',
        bottom:0
      }}
      imageStyle={{
      resizeMode: "cover",
      alignSelf: "flex-start"
  }}>
    <Text style={{ color: "#D8D8D8", fontSize: 16 }}>Login</Text>
</ImageBackground>

我不需要填充文本,如果可以在没有 ImageBackground 的情况下做到这一点,那也很棒。

4

0 回答 0