0

line one and line two are different TextViews separated with a 8dp margin vertically

line three and four is one TextView that uses a SpannableString. Is there a way i can add the same spacing(8dp) with a Span?

I tried using a LineHeightSpan, the result is the image below.

append("line three")
appendLine()
appendLine()
setSpan(
    LineHeightSpan.Standard((8 * resources.displayMetrics.density).toInt()),
    0,
    length,
    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
append("line four")

enter image description here

Puntogris
  • 325
  • 2
  • 13
  • [This](https://stackoverflow.com/questions/32078831/how-can-i-add-margin-or-padding-between-2-lines-in-spannable) could help – Zain Apr 17 '22 at 16:47

1 Answers1

0

Please code below code.

append("line three")
append("\n")
append("\n")
setSpan(
    LineHeightSpan.Standard((8 * resources.displayMetrics.density).toInt()),
    0,
    length,
    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
append("line four")
Sumit Kumar
  • 263
  • 1
  • 6