【问题标题】:Vertically align a component in React Native在 React Native 中垂直对齐组件
【发布时间】:2021-05-01 01:21:11
【问题描述】:

我希望我的项目像这样对齐:

但不知何故它是这样的:

代码是:

 <View style={{flex: 1}}>
  <View style={{flexDirection: 'row'}>
    <Component.CircledIcon
       source={iconSource}
    />
    <Component.Text style={{fontWeight: 'bold',
      fontSize: '$regular',
      color: '$body',
      flex: 1,
      marginRight: '2.5rem',
      paddingBottom: '1rem',
    }}>
      {name}
    </Component.Text>
  </View>
 </View>

【问题讨论】:

    标签: reactjs react-native flexbox react-native-flexbox


    【解决方案1】:

    你只需将一个属性添加到组件的父级中(在您看来。)

    justifyContent:"space-between"
    

    请参考此链接,这可能有助于您理解样式。

    (React-Native 样式备忘单)[https://github.com/vhpoet/react-native-styling-cheat-sheet]

    【讨论】:

      【解决方案2】:

      试试这个:-

      <View style={{flex: 1}}>
      <View style={{flexDirection: 'row'
      alignItems:"center"  //add this line to your code
       }>
      <Component.CircledIcon
         source={iconSource}
      />
      <Component.Text style={{fontWeight: 'bold',
        fontSize: '$regular',
        color: '$body',
        flex: 1,
        marginRight: '2.5rem',
        paddingBottom: '1rem',
      }}>
        {name}
      </Component.Text>
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-06
      • 2020-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多