【问题标题】:How do I remove default padding on textView?如何删除 textView 上的默认填充?
【发布时间】:2018-10-17 04:11:03
【问题描述】:

所以,这个问题是重复的,但我读过的答案对我不起作用。如果事实上,他们似乎也没有为其他人工作,所以我再试一次,看看是否有人知道答案。

添加一个textView时,它看起来像

如您所见,蓝色布局标记和实际文本之间肯定有很多空间。当将一个textView 放在另一个之上时,空间变得非常明显。请注意,这是在我添加了 XML 代码行之后:

android:includeFontPadding="false"

(在小范围内有效)和:

android:lineSpacingExtra="0dp"

(据说根据其他线程解决了问题,但由于某种原因对我没有任何作用)。

textView 的完整 XML 是:

<TextView
    android:id="@+id/healthTextId"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:fontFamily="sans-serif"
    android:includeFontPadding="false"
    android:lineSpacingExtra="0dp"
    android:text="Test"

    android:textAlignment="center"
    android:textColor="@color/colorHealth"

    android:textSize="100dp"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

默认字体和自定义字体都存在此问题。有什么想法吗?

这是我读到的一个帖子,不幸的是它没有为我解决问题:Android: TextView: Remove spacing and padding on top and bottom

【问题讨论】:

  • 如果你的字体有自己的填充,你不能删除它。你试过不同的字体吗?
  • 是的,我已经尝试过自定义和默认字体...
  • 你能解决这个问题吗?

标签: android textview padding


【解决方案1】:

这个问题很烦人。即使您删除所有填充,字体本身的填充仍然存在。试试this answer。这是一个很好的方法。

【讨论】:

    【解决方案2】:

    只需android:padding="0dp" 即可。

    【讨论】:

      猜你喜欢
      • 2017-04-23
      • 1970-01-01
      • 2023-02-08
      • 2020-05-16
      • 2015-10-24
      • 2020-06-11
      • 1970-01-01
      • 2015-11-11
      • 2019-07-09
      相关资源
      最近更新 更多