首页 文章

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

提问于
浏览
1

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

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 回答

  • 1

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

    PS . 您可能希望在包含按钮的视图上添加一些填充

    你会有类似的东西:

    <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>
    

相关问题