How to justify (left, right, center) each child independently?

前端 未结 4 2033
死守一世寂寞
死守一世寂寞 2020-12-08 01:46

In react native I have:


  {\'<\'}
    
      Fitness &a         


        
相关标签:
4条回答
  • 2020-12-08 02:22

    use this

    marginLeft: "auto",
    marginRight: "auto"
    
    0 讨论(0)
  • 2020-12-08 02:26

    One way is to use nested View (flex containers) for 3 different regions and set flex:1 to left and right region

    <View style={styles.navBar}>
      <View style={styles.leftContainer}>
        <Text style={[styles.text, {textAlign: 'left'}]}>
          {'<'}
        </Text>
      </View>
      <Text style={styles.text}>
        Fitness & Nutrition Tracking
      </Text>
      <View style={styles.rightContainer}>
        <View style={styles.rightIcon}/>
      </View>
    </View>
    
    const styles = StyleSheet.create({
      navBar: {
        height: 60,
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center',
        backgroundColor: 'blue',
      },
      leftContainer: {
        flex: 1,
        flexDirection: 'row',
        justifyContent: 'flex-start',
        backgroundColor: 'green'
      },
      rightContainer: {
        flex: 1,
        flexDirection: 'row',
        justifyContent: 'flex-end',
        alignItems: 'center',
        backgroundColor: 'red',
      },
      rightIcon: {
        height: 10,
        width: 10,
        resizeMode: 'contain',
        backgroundColor: 'white',
      }
    });
    

    0 讨论(0)
  • 2020-12-08 02:29

    If you're using a NavigationBar from the Navigator module see my question: Changing the default style for a Navigator.NavigationBar (title)

    0 讨论(0)
  • 2020-12-08 02:34

    You could also set marginLeft: 'auto' to the middle component. It should push it to the right. Also works for React Native

    Source: https://hackernoon.com/flexbox-s-best-kept-secret-bd3d892826b6

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