V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
aiyov
V2EX  ›  React

ReactNative 之 Text 组件 LineHeight 问题

  •  
  •   aiyov · 2018-03-14 17:20:41 +08:00 · 4908 次点击
    这是一个创建于 2228 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Text 组件 lineHeight 与 height 相等,一般来讲,text 组件字体应该垂直居中,但是我这里却是字体底部对齐 text 组件。

    添加 lineHeight 之前效果如下 添加 lineHeight 之前

    添加 lineHeight 之后效果如下 添加 lineHeight 之后

    代码如下

      <View style={styles.container}>
        <Text style={styles.welcome}>
        Welcome to React Native!
        </Text>
      </View>
          
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
      },
      welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
        height: 60,
        // lineHeight: 60,
        backgroundColor: 'green',
      }
    

    请教一下为什么会出现这种现象?

    1 条回复    2018-03-15 14:14:04 +08:00
    aiyov
        1
    aiyov  
    OP
       2018-03-15 14:14:04 +08:00
    已解决,rn 版本问题,0.51 及以下都存在这个问题。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4514 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:05 · PVG 18:05 · LAX 03:05 · JFK 06:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.