Android lineHeight 与 lineSpacingExtra

标签 android textview styles

我能知道android xml中的lineHeight和lineSpacingExtra有什么区别吗?我试图比较两者,但得到了不同的结果(我需要 lineHeight 函数,但它仅在 API 28 中受支持)。

这是我的部分代码:

左:

android:textSize="14sp"

android:lineSpacingExtra="6dp"

右:

android:textSize="14sp"

android:lineHeight="20dp"

结果:

enter image description here

有什么解决办法吗? 谢谢。

最佳答案

你提到你想在 pre-API 28 中设置 lineHeight,另一种方法是只设置一个小的 lineSpacingExtra/lineSpacingMultiplier值(如您所示)。否则,在this related question中有很多自己设置行高的解决方案.

我将在下面通过我的总结和官方文档简要介绍差异。

android:lineHeight 是每一行的总高度。这包括文本以及顶部和底部的任何填充。

Explicit height between lines of text. If set, this will override the values set for lineSpacingExtra and lineSpacingMultiplier.

android:lineSpacingExtra 是在每行文本(最后一行除外)之后添加的附加间距。

Extra spacing between lines of text. The value will not be applied for the last line of text.

最后,你可能会对android:lineSpacingMultiplier感兴趣。这类似于 lineSpacingExtra,但具有当前高度的乘数值(例如 1.2)而不是固定值。

Extra spacing between lines of text, as a multiplier. The value will not be applied for the last line of text.

可获得更多信息(除了包含的配额之外)in the TextView documentation .

关于Android lineHeight 与 lineSpacingExtra,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54197632/

相关文章:

android - 将 SwipeView 用于布局而不是图像

Android 日历 : created an event using intent , 但它不会返回到我的 Activity

java - R.java 错误

android - 一般如何动态更改 TextVIew 和 UI?

css - Bootstrap Image 扩展到列容器之外

html - 在每个元素之后使用样式标签编码电子邮件签名?

WPF - 如何对裁剪后的图像应用效果?

android - ActionBar 向上指示器位于何处

java - 创建 Formatter 对象失败

android - 如何使用默认选项复制并全选以编程方式启动 textview 的上下文操作栏?