【问题标题】:Does the font affects the height of the TextView?字体会影响 TextView 的高度吗?
【发布时间】:2020-03-04 09:56:31
【问题描述】:

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

例如,在三星 Galaxy 中,您可以更改设备字体,而我的整个布局取决于此 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" />

【问题讨论】:

    标签: java android fonts textview


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      推荐给我们sp字体大小和dp休息。

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

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

      android:textSize="14sp"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-04-10
        • 1970-01-01
        • 2012-08-27
        • 2021-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-05
        相关资源
        最近更新 更多