Is it possible to define individual line spacings for each text line of a TextView?
Example:
TextView tv = new TextView(context);
tv.set
Android 10 (API 29) added LineHeightSpan.Standard to do set an absolute line height. If you need backward compatibility, use the following implementation which I based on LineHeightSpan.Standard:
private static class AbsoluteHeightSpan implements LineHeightSpan {
private final int _height;
AbsoluteHeightSpan(int height) {
_height = height;
}
@Override
public void chooseHeight(CharSequence text, int start, int end, int spanstartv, int v, FontMetricsInt fm) {
final int originHeight = fm.descent - fm.ascent;
// If original height is not positive, do nothing
if (originHeight <= 0)
return;
final float ratio = _height * 1.0f / originHeight;
fm.descent = Math.round(fm.descent * ratio);
fm.ascent = fm.descent - _height;
}
}