react-native - 如何在 React Native 中设置 `ImageBackground` 图像位置。就像在 css `background-postion: bottom` 中一样?

标签 react-native

所以我在 react native 中设置背景图像,但我需要将背景图像的位置设置为底部。所以如果有人知道如何实现这一点。

我曾尝试添加 backgroundPosition 但它似乎不受支持

<ImageBackground
  source={require("../assets/img/bg-top.png")}
  // resizeMethod={'auto'}
  style={{
    width: "100%",
    height: 120,
    padding: 20,
    paddingVertical: 40,
    backgroundPosition: "bottom" // not working
  }}
  imageStyle={{
    resizeMode: "cover",
    alignSelf: "flex-end"
  }}
>
  <Text style={{ color: "#D8D8D8", fontSize: 16 }}>Login</Text>
</ImageBackground>;


我希望图像对齐应该从底部开始,而不是从顶部开始

最佳答案

React Native 提供 底部职位标记以在底部设置 UI。请将 backgroundPosition 标签从图像样式替换为

位置:'绝对',
底部:0

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

请检查小吃博览会

https://snack.expo.io/@vishal7008/bottom-ui

关于react-native - 如何在 React Native 中设置 `ImageBackground` 图像位置。就像在 css `background-postion: bottom` 中一样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55673291/

相关文章:

react-native - 将 PayPal 与 React Native 集成

javascript - 如何从外部 .js 文件加载屏幕?

react-native - opneUrl react native 链接调用,mailto

android - 适用于 Android 的 React-Native Twitter 登录

android - 在 Android-React native 中处理不同屏幕尺寸的问题

javascript - 我可以告诉 useMemo 跳过其依赖项数组中的空值吗?

javascript - 如何加载动态数据到react-native-chart-kit?

javascript - 如何仅在 View 内部的图像完成渲染时渲染 View ,同时显示渲染指示器?

react-native - 如何禁用可触摸组件中子元素的触摸

android - react native 错误:undefined is not a function (evaluating 'this._pressRow()' )