React Native absolute positioning horizontal centre

后端 未结 7 764
栀梦
栀梦 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:39

    create a full-width View with alignItems: "center" then insert desired children inside.

    import React from "react";
    import {View} from "react-native";
    
    export default class AbsoluteComponent extends React.Component {
      render(){
        return(
         
          {this.props.children}
             
        )
      }
    }
    

    you can add properties like bottom: 30 for bottom aligned component.

提交回复
热议问题