【发布时间】:2016-04-23 11:50:35
【问题描述】:
我有两段文字。我需要第一块水平和垂直居中,第二块就在它旁边。目前代码如下所示:
<View style={styles.runningTimeWrapper}>
<Text style={styles.loggedTime}>00:00</Text>
<Text style={[styles.loggedTime, styles.loggedSeconds]}>00</Text>
</View>
如何设置样式以使 00:00 居中?使用固定宽度不是一个选项,因为我需要它在任何屏幕尺寸上工作。
这是它目前的样子:
样式:
loggedTime: {
color: Variables.PURPLE,
fontSize: 44,
alignSelf: 'center',
},
loggedSeconds: {
fontSize: 22,
alignSelf: 'flex-end',
paddingBottom: 8
},
runningTimeWrapper: {
flexDirection: 'row',
justifyContent: 'center',
flex: 1,
},
想要的效果是让 hh:mm 的列与屏幕中心对齐,秒紧挨着分钟。
在所有“中心”引用中,我说的是水平中心(x 轴),而不是垂直(y 轴)(使用 alignItems /self 设置)
【问题讨论】:
标签: css react-native flexbox