Insert line separator in spannablestringbuilder af

2019-08-08 20:41发布

I have a spannablestringbuilder with a number of imagespans in it. I would like to insert a line separator after the image to ensure that text following it starts on the next line.

I am trying to do this in a loop, but it doesn't insert the line seprator and breaks the spans.

ImageSpan[] imageSpans = strBuilder.getSpans(0, strBuilder.length(), ImageSpan.class);
    for (ImageSpan imageSpan : imageSpans) {
        strBuilder = strBuilder.insert(strBuilder.getSpanEnd(imageSpan), System.getProperty("line.separator") );
    }

Any ideas?

1条回答
地球回转人心会变
2楼-- · 2019-08-08 21:02

My issue was that I was adding new ImageSpans elsewhere in the code and not removing previously added ones. This led to the inconsistencies, removing old imagespans after adding a new one resolved the issue.

查看更多
登录 后发表回答