Two buttons sharing a row in react-native

后端 未结 1 2003
再見小時候
再見小時候 2021-02-06 04:17

I have two buttons that look like this

This is the code

render = () => (
    

        
相关标签:
1条回答
  • 2021-02-06 05:03

    You'd need to define a container with flexDirection set to row and use justifyContent depending on where you want your padding:

    render() {
      return (
        <View style={styles.container}>
          <View style={styles.button} />
          <View style={styles.button} />
        </View>
      );
    }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        flexDirection: 'row',
        justifyContent: 'space-between'
      },
      button: {
        backgroundColor: 'green',
        width: '40%',
        height: 40
      }
    });
    

    Change space-between to space-around if you want the padding to be distributed to the sides too. (Demo)

    0 讨论(0)
提交回复
热议问题