对齐按钮与侧面相等并对齐

时间:2018-02-04 20:11:01

标签: react-native

我需要使按钮宽度相等,如果可能的话,对齐容器的边缘。

enter image description here

我尝试过以下方面没有成功:

<View style={{flex: 1,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center'}>

   <View  style={{flex: 1}}>
      <Button title="Button 1"/>
   </View>

   <View  style={{flex: 1}}>
      <Button title="Button 2"/>
   </View>
</View>

我错过了什么?

1 个答案:

答案 0 :(得分:1)

对于宽度,您只需将按钮的宽度设置为100%即可。 如果我通过将它们与边缘对齐来正确理解您的意思,则可以在容器上使用justifyContent: 'space-between'

聚苯乙烯。您可能希望在包含按钮的视图上添加一些填充

你会有类似的东西:

<View style={{flex: 1,
  flexDirection: 'row',
  alignItems: 'center',
  justifyContent: 'space-between'}>

  <View  style={{flex: 1}}>
    <Button title="Button 1" style={{width: "100%"}}/>
  </View>

  <View  style={{flex: 1}}>
    <Button title="Button 2" style={{width: "100%"}}/>
  </View>
</View>