Paragraph spacings using SpannableStringBuilder in TextView

空扰寡人 提交于 2019-11-30 14:30:30

Implement the LineHeightSpan and override chooseHeight method as follows

@Override
public void chooseHeight(CharSequence text, int start, int end,
        int spanstartv, int v, FontMetricsInt fm) {
    Spanned spanned = (Spanned) text;
    int st = spanned.getSpanStart(this);
    int en = spanned.getSpanEnd(this);
    if (start == st) {
        fm.ascent -= TOP_SPACING;
        fm.top -= TOP_SPACING;
    }
    if (end == en) {
        fm.descent += BOTTOM_SPACING;
        fm.bottom += BOTTOM_SPACING;
    }
}

Don't forget to add \n at the end of your each paragraph text.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!