Insert line separator in spannablestringbuilder after imagespans (Android)

孤街浪徒 提交于 2019-12-24 06:39:46

问题


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

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