【发布时间】:2019-12-29 16:34:52
【问题描述】:
我想在具有明确高度的视图中将文本垂直居中。
Center text vertically in react-native 没有完全回答我的问题,因为他们没有使用明确的高度。
当我使用时
<View style={styles.rightContainer}>
<Text style={styles.label2}>
Centered
</Text>
</View>
rightContainer: {
marginRight: 10,
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-end',
alignItems: 'center',
},
label2: {
height: 40,
backgroundColor: 'green',
textAlignVertical: 'center',
},
如果我去掉显式高度,
label2: {
backgroundColor: 'green',
textAlignVertical: 'center',
},
它有效。
我需要设置显式高度,因为我会将此视图转换为可点击的按钮。
我该如何进行这项工作? 我对 react-native 布局有什么误解?
【问题讨论】:
-
你不能用
marginTop:height/2吗?
标签: css react-native flexbox react-native-flexbox