Reputation: 343
I'm using ListItem imported from native-base. ListItem is red and it's child View is yellow. As you can see from the screenshot, View style does not take entire width of ListItem, despite having a flex: 1. How can I make it so that View take entire width of ListItem?
<List>
<ListItem style={[styles.listitem, { backgroundColor: "red" }]}>
<View
style={{
flex: 1,
flexDirection: "column",
backgroundColor: "yellow"
}}
>
<Text style={styles.timeInfoHeader}>{this.props.totalUsage}</Text>
<Text style={styles.timeInfoSubHeader}>Total (hrs)</Text>
</View>
</ListItem>
</List>;
Stylesheet:
timeInfoHeader: {
fontSize: 40,
color: 'rgba(45, 145, 176, 100)',
textAlign: 'center'
},
timeInfoSubHeader: {
fontSize: 12,
color: 'rgba(209, 209, 209, 100)',
paddingBottom: 4,
marginBottom: 4,
textAlign: 'center'
},
listitem: {
width: '100%',
marginLeft: 0
},
Upvotes: 6
Views: 22602
Reputation: 1391
Try this code snippet:
<ScrollView contentContainerStyle={{ flexGrow: 1 }} >
<View style={{ flex: 1 }} >
...
</View >
</ScrollView >
Upvotes: 2
Reputation: 608
What causes this is the textAlign
style on the timeInfoHeader
. So you can either remove the textAlign
style from timeInfoHeader
or add a width: "100%"
to listitem
. Just glancing at your code, it seems you might be better off adding the textAlign
to the child View of timeInfoHeader
.
Upvotes: 0