React Native absolute positioning horizontal centre

后端 未结 7 768
栀梦
栀梦 2021-01-30 06:23

It seems that with position:absolute in use an element cannot be centred using justifyContent or alignItems. There\'s a workaround to use

7条回答
  •  离开以前
    2021-01-30 06:48

    You can center absolute items by providing the left property with the width of the device divided by two and subtracting out half of the element you'd like to center's width.

    For example, your style might look something like this.

    bottom: {
        position: 'absolute',
        left: (Dimensions.get('window').width / 2) - 25,
        top: height*0.93,
    }
    

提交回复
热议问题