10

Is there a way to achieve lineSpacing in Jetpack Compose? Similar to normal Android's lineSpacingExta and lineSpacingMuliplier?

I'm aware there is lineHeight in Text and TextStyle, but that is not the same thing. Line Height specifies how big each line should be, not the space between a line and the next one.

For example, line height applies to the last line, while line spacing would not, because there is no like after it

Anatolii Chub
  • 1,228
  • 1
  • 4
  • 14
Ahmad Sattout
  • 2,248
  • 1
  • 19
  • 42
  • Maybe you can look at [How to set line-space with Android Jetpack Compose Text()?](https://stackoverflow.com/questions/64741988/how-to-set-line-space-with-android-jetpack-compose-text) – Ognjen Drljača Jul 07 '21 at 19:52

1 Answers1

1

While there is no direct equivalent to lineSpacingExtra and lineSpacingMultiplier, there are many ways to control the height of a line in Compose. I suggest reviewing this article for the full background of the api design: Fixing font padding in Compose Text

Excerpts:

We had the following goals:

Removing unnecessary paddings, giving the control back to you to implement the paddings you really need. Automatically preventing clipping issues for tall scripts, italic fonts, etc. So we released changes that included:

  • Creating a new API PlatformTextStyle to allow to switch includeFontPadding on and off (default value is true).
  • To fix all tall fonts clipping issues that could happen from turning includeFontPadding off in Compose, we apply additional padding when required for only the first and last line, and the max line height is calculated based on the font(s) that is used for all the text included in a given line (instead of the FontMetrics of the first font in the font fallback).

....

LineHeightStyle controls how to distribute the line height in each line of text and whether line height is applied to the top of the first line and to the bottom of the last line. It defines the alignment of lines in the space provided by TextStyle(lineHeight) and offers several options to be able to modify your text’s behavior within the available draw space.

beyondtheteal
  • 729
  • 6
  • 15