javascript - react native 绝对定位不起作用

标签 javascript css reactjs react-native

我在下面代码中的按钮是绝对定位的,但它不起作用。它正在占用其包含 View 中的空间,并且不允许图像位于其下方。

<View style={{
  justifyContent: 'flex-end',
  alignItems: 'center',
  flexDirection: 'row',
  flex: 0.5,
  borderRadius: 8
}}>

  <Image
    style={mapStyles.avatar}
    source={props.image} />

  <Button
    small
    icon
    style={{
      positon: 'absolute',
      right: -5,
      top: -5,
      width: 20,
      height: 20,
      zIndex: 50,
      elevation: 10,
      borderRadius: 10,
      backgroundColor: '#FF3B3F',
      shadowColor: '#000000',
      shadowOffset: {
        width: 0,
        height: 1
      },
      shadowRadius: 1,
      shadowOpacity: 1.0
    }}
    onPress={() => props.updateImage(null)}>
    <Icon style={locationStyle.deleteLocationButtonIcon}
      name="close-o" size={22} color="#9E9E9E" />
  </Button>

</View>

按钮是粉色位:enter image description here

按钮需要在图片的右上角,是一个取消按钮。图像应该位于按钮所在的最右侧。我以前经历过绝对定位在 React Native 中不起作用。这是错误还是我做错了?

图像样式:

  avatar: {
    width: 100,
    height: 100
  }

最佳答案

尝试将按钮嵌套在图像中,例如

<Image>
  <Button />
</Image

关于javascript - react native 绝对定位不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44043766/

相关文章:

html - 样式表上是否允许延迟或异步包括?

javascript - 使用jsp和oracle数据库创建登录选项

javascript - 如何提交表单并在当前页面的 Div 内加载目标页面?

javascript - 捕获 promise 而不拒绝

jquery - 使导航向左浮动的问题

javascript - 在 React Bootstrap 中处理下拉项选择

javascript - 将 JavaScript 字符串变量转换为小数/货币

html - 很难修复具有动态内容的 div 的高度

javascript - 如何在自定义 Hook 中测试 useEffect?

reactjs - useMatch 用于在react-router-dom 中测试多种模式