从Android Developer的角度解释这一点.
行高通常表示文本大小+"填充"顶部/底部.
因此,如果您的设计师编写行高19sp和文本大小15sp,则意味着您需要额外填充4sp.
19sp-15sp = 4sp.
要在布局中实现它,请使用lineSpacingExtra
属性.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:lineSpacingExtra="4sp"
android:fontFamily="sans-serif"
tools:text="StackOverflow is awesome"
/>
实现线高的另一种方法是使用比例.例如,1.2
.这意味着,间距是文本大小的120%.
在上面的示例中,行高为19sp,文本大小为15sp.如果我们把它翻译成规模,那就变成了.
19/15 = 1.26
要在布局中实现它,请使用lineSpacingMultiplier
属性.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:lineSpacingMultiplier="1.26"
android:fontFamily="sans-serif"
tools:text="StackOverflow is awesome"
/>