0

I use setLineSpacing() to increase the space between lines in a textView, and it seems okay when I test it with Pixel API 25 emulator, but when I test it with Nexus 6p API 23, it's good till a new line (\n) happens. Then after that, the space between line gets reset. It's like setLineSpacing affects just a part of text(the first paragraph). Why does this happen?

if (android.os.Build.VERSION.SDK_INT >= 23) {
        textView.setLineSpacing(textView.getLineHeight(), 0.6f);
}

UPDATE: I kindof found the problem, but no solution so far. I use span to make the first letter in my textView bigger.

wordtoSpan.setSpan(new RelativeSizeSpan(2f), 2, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

Actually, setLineSpacing method does increase the line spacing for the whole text view but there is an extra line spacing for the first line till "\n" because of making the first letter bigger by setSpan. It only happens in older APIs like 23 tho.

  • I may be wrong, but isn't the second argument for `setLineSpacing` supposed to be the line spacing multiplier? So if you want to increase the spacing, it should be greater than `1.0f`. Does that do anything? – Brian Jan 17 '18 at 21:49
  • @Brian Not really. It means the space between lines will be textView.getLineHeight() + (textView.getLineHeight() * 0.6) – Aria Vaghef Jan 17 '18 at 22:08
  • I see, hmm then I'm not too sure what's going on. :/ – Brian Jan 17 '18 at 22:15
  • @Brian Read the last paragraph. It's not because of setLineSpacing, but it happens because I made the first letter bigger in my textView by setSpan. – Aria Vaghef Jan 17 '18 at 22:51

1 Answers1

0

After several tests, I found out this problem happens only in API 23. So I concluded that this bug exists only in this API level. The text view looks fine on API 21, 22, 24, 25, 26 and 27.