javascript - 在 React Native 中垂直对齐文本
问题描述
我想让我的文字在图片中变成这样。但我的文字没有垂直居中。如何实现?
到目前为止我所做的是
<Fragment>
<HeaderMain navigation={navigation}/>
<View style={styles.subheader}>
<Text style={styles.topText}>Заказы</Text>
</View>
</Fragment>
风格
container: {
flex: 1,
paddingHorizontal: 8,
paddingVertical: 7,
backgroundColor: '#E5E5E5',
},
subheader:{
height: 55,
backgroundColor: '#ffffff',
flexDirection: 'column',
},
topText:{
fontWeight: "bold",
fontSize: 17,
lineHeight:21,
fontFamily: MONREGULAR,
marginLeft: 16,
justifyContent: 'center',
alignItems: 'center',
},
解决方案
你不应该使用justifyContent
,alignItems
在Text
. 你应该在View
. 还要给 lineHeight 与你的 fontSize 相同的值。像这样;
subheader:{
height: 55,
backgroundColor: '#ffffff',
flexDirection: 'column',
justifyContent: 'center',
},
topText:{
fontWeight: "bold",
fontSize: 17,
lineHeight: 21,
fontFamily: MONREGULAR,
marginLeft: 16,
},
推荐阅读
- android - 找不到属性“android:text”的设置器 - Android MVVM
- algorithm - QuickSort 分区枢轴异常
- redis - Redis - 一个请求中具有多个弹出的可靠队列模式
- php - Google drive API 不允许在未经 PHP 身份验证的情况下上传文件
- excel - VBA为什么if函数不按特定短语过滤我的数据
- python - 如果出错,返回同一窗口 Python Tkinter 2.7
- django - 如何在表单中过滤 Choice FK?
- html - 悬停时图像上的文本受滤镜亮度影响
- groovy - 使用 groovy 验证列和数据类型的断言
- walmart-api - 沃尔玛杂货店的开发人员 API