I wanna add multiple span to a textview with configurable line space. I use LineHeightSpan class defined in android. But it seems it behave differently in Android M and lower versions Here the result in lower version of Android
and this is how it looks like in Android M
Here is how I implemented in code: This is my implementation of LineHeightSpan:
public class VerticalMarginSpan implements LineHeightSpan {
private final int value;
public VerticalMarginSpan(int value) {
this.value = value;
}
@Override
public void chooseHeight(CharSequence text, int start, int end, int spanstartv, int v,
Paint.FontMetricsInt fm) {
fm.ascent -= value / 2;
fm.descent += (value / 2);
}
}
And how I use it:
SpannableStringBuilder builder = new SpannableStringBuilder(tempStr);
builder.setSpan(
new VerticalMarginSpan(lineSpace),
0,
tempStr.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
txt.setText(builder);
How I can fix the problem?