【发布时间】:2018-02-02 08:09:05
【问题描述】:
试图在 react-native 中构造一个标头。我已经做到了这一点,但我想让标题居中并且正确的文本右对齐。有没有使用 flexbox 的简单组合来实现这一点?
<View style={{marginTop: 20, backgroundColor:'yellow'}}>
<View style={{flex: 1, flexDirection: 'row', alignItems:'center', justifyContent:'space-between', marginTop: 20, marginBottom: 20, borderColor:'red', borderWidth:1}}>
<Text style={{ flex: 1, alignItems:'center', justifyContent:'center', borderColor:'red', borderWidth:1}}>Left with long text</Text>
<Text style={{ flex: 1, alignItems:'center', justifyContent:'center', borderColor:'red', borderWidth:1}}>Title</Text>
<Text style={{ flex: 1, alignItems:'center', justifyContent:'center', borderColor:'red', borderWidth:1}}>Right</Text>
</View>
</View>
【问题讨论】:
-
“我想让标题居中”是什么意思?
-
textAlign: 'right'将修复“正确”文本。现在怎么不居中了? -
你希望标题是什么样子的任何图片?
-
顺便说一句,
justifyContent:'center',可能会覆盖第三项的textAlign,因此如果保留justifyContent,请将其设为justifyContent:'flex-end',
标签: layout react-native flexbox