【问题标题】:React Native - Adjust the font size based on the size of the container on AndroidReact Native - 根据容器大小在 Android 上调整字体大小
【发布时间】:2019-04-30 15:10:29
【问题描述】:

我正在尝试将文本放入有限的空间(黄色容器)。 Android中this problem如何解决?

在 iOS the problem is solved 中使用 adjustsFontSizeToFit={true}。

我的代码:

<View
  style={{
    backgroundColor: 'yellow',
    flex: 0.8,
    marginRight: 10,
    flexDirection: 'column',
    justifyContent: 'center',
    alignItems: 'center'
  }}
>
  <CustomText style={{ fontWeight: '400' }}>{`Qt. ${orderProduct.quantity}`}</CustomText>
    <PriceText
      style={{
        fontWeight: '600',
        fontSize: 18,
        color: '#000'
      }}
      price={price}
    />
</View>

【问题讨论】:

标签: javascript android react-native


【解决方案1】:

您可以考虑调查this。 在 android native 中,它是通过将文本的最大行数设置为 1 来完成的。android:maxLines="1"

【讨论】:

  • 在 react native 中使用 numberOfLines={1} 完成相同的操作,但结果不是我想要的。例如,如果价格很长,那么它将被截断为 '...' (12923.3...)
  • 是的,这是通常的行为。您必须设置特定布局的宽度。
猜你喜欢
  • 2012-11-11
  • 2019-03-27
  • 2020-01-27
  • 2013-08-28
  • 1970-01-01
  • 2011-04-04
  • 2012-11-01
  • 2014-04-29
  • 2017-11-02
相关资源
最近更新 更多