问题
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:
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.
来源:https://stackoverflow.com/questions/30290932/insert-line-separator-in-spannablestringbuilder-after-imagespans-android