字体会影响 TextView 的高度吗?

Does the font affects the height of the TextView?

如果我为 android:textSize 使用固定的 DP 和固定数量的 android:lines,这是否意味着 对于同一设备,我的 TextView 的高度将保持不变,无论使用哪种字体? 我在 phone 上测试的所有字体都表明是这种情况,但我不确定。

例如,在 Samsung Galaxy 中,您可以更改设备字体,我的整个布局取决于此 TextView 大小,我需要知道是否会出错。

这是 TextView:

<androidx.appcompat.widget.AppCompatTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="top|center_horizontal"
        android:maxWidth="80dp"

        android:lines="2"
        android:textSize="14dp"

        android:layout_gravity="top|center_horizontal"
        android:ellipsize="end" />

首先不要将 dp 用于文本大小,始终在 sp 中使用,是的,字体样式对大小有影响,但如果您使用 wrap_content 则影响不大,它需要宽度和高度作为其要求。

建议我们 sp 字体大小和 dp 休息。

sp 类似于 dp 单位,但它也会根据用户的字体大小偏好进行缩放。建议您在指定字体大小时使用此单位,这样它们将根据屏幕密度和用户偏好进行调整。

更改您的 TextView 文字大小,如下所示 -

android:textSize="14sp"