Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

align center a checkbox in a View (RN)

My code is:

      <View style={{...styles.tableRow, backgroundColor: index % 2 == 1 ? "#F0FBFC" : "white"}}>
        <View style={styles.checkboxContainer}>
          <Checkbox label="" color="success" checkboxStyle={styles.checkbox}/>
        </View>
        <Text style={styles.columnRowTxt}>{members[item].first}</Text>
        <Text style={styles.columnRowTxt}>{members[item].last}</Text>
        <Text style={styles.columnRowTxt}>{item.Weight}</Text>
      </View>

I’m attempting to align the Checkbox in the center of that View. I originally tried it with out a view. Here is my style:

  checkbox: {
    backgroundColor: "yellow",
  },
  checkboxContainer: {
    flexDirection: "row",
    width: "25%",
    backgroundColor: "gray",
    alignItems:"center"
  }

The result is:
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have also tried:
checkbox: {
backgroundColor: "yellow",
alignSelf: "center",
},

How can I get that centered?

>Solution :

alignItems: "center" 

should be:

justifyContent: "center" 

justifyContent goes with the flexDirection, alignItems goes opposed to the flexDirection.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading