0

I have a custom TextView that combines two pieces of text and have a spacing variable.

class MyCustomTextView() {

  var label: String
  var value: String
  var spacingBetweenLabelAndValue: Int = 0

  // ...
}

Each one have their own style and are concatenated. Example:

  • label -> "Name:"
  • value -> "John"
this.text = Spanny(label, *labelTextSpannables)
      .append(value, *valueTextSpannables)

which in the end is resulting in "Name:John"

I want to add an extra spacing (spacingBetweenLabelAndValue) between those two strings.

"Name:(spacing here)John"

Is there a way to do this using Spannable?

Augusto Carmo
  • 4,386
  • 2
  • 28
  • 61

1 Answers1

0
 SpannableStringBuilder("label")
.append(String.format("%1$" + spacingBetweenLabelAndValue + "s", ""))
.append(SpannableString("value"))
Ali
  • 1,462
  • 2
  • 14
  • 16