javascript - 在 React Native 中垂直对齐文本

标签 javascript css reactjs react-native

enter image description here我想在图片中制作这样的文字。但是我的文字没有垂直居中。如何实现?

到目前为止我所做的是

<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',
},

最佳答案

您不应在 Text 中使用 justifyContentalignItems。您应该在 View 中使用它。还为 lineHeight 提供与 fontSize 相同的值。像这样;

subheader:{
    height: 55,
    backgroundColor: '#ffffff',
    flexDirection: 'column',
    justifyContent: 'center',
},

topText:{
    fontWeight: "bold",
    fontSize: 17,
    lineHeight: 21,
    fontFamily: MONREGULAR,
    marginLeft: 16,
},

关于javascript - 在 React Native 中垂直对齐文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58624667/

相关文章:

css - 屏幕中间的 HTML 列

javascript - 为什么当我使用 .map 而不是硬编码来动态填充内容时,Material UI 选项卡停止工作?

javascript - 在构建 knockout js 绑定(bind)时隐藏屏幕的最佳方法是什么?

javascript - 在angulajs中转换java对象中的json时,获取嵌套异常是com.fasterxml.jackson.databind.JsonMappingException

JavaScript:如何从事件中调用函数

javascript - 如何将 css 文件添加到页面正文?

javascript - 使用 Javascript 添加 CSS

html - 如何根据百分比获得2种背景颜色,我选择

css - 如何使用 :global css classes - css modules

javascript - 根据折线图中的数据,点的放置并不完美