React Native绝对定位水平中心

兔子:

似乎position:absolute在使用中某个元素无法使用justifyContent居中alignItems有一种解决方法可以使用,marginLeft但即使使用尺寸来检测设备的高度和宽度,也无法在所有设备上显示相同的结果。

  bottom: {
    position: 'absolute',
    justifyContent: 'center',
    alignItems: 'center',
    top: height*0.93,
    marginLeft: width*0.18,
  },
  bottomNav: {
    flexDirection: 'row',
  },
斯蒂芬·霍瓦斯(Stephen Horvath):

将您想要的孩子包裹在View中居中,然后将View设为绝对。

<View style={{position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, justifyContent: 'center', alignItems: 'center'}}>
  <Text>Centered text</Text>
</View>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章