android imagespan not support auto next line

377 Views Asked by At

android ImageSpan, in textview when last position show a big image is little,but my image is very big,I want to the ImageSpan auto next line . I try overload size method and change size equal textview width, but doesn't solve the problem

SpanabeleString contentSS=new SpanabeleString("hello word on the line [image]");
contentSS.setSpan(imageSpan,"[image]".start,"start".length,xxx);
//imageSpan not support auto new line;

I cannot change content,I hope use imagespan implement auto next line function

1

There are 1 best solutions below

4
Cheticamp On

An ImageSpan is an indirect subclass of ReplacementSpan. Flowing onto a new line is, evidently, something that ReplacementSpan (therefore an ImageSpan) cannot do. Here is a quote from an article Drawing a rounded corner background on text by Florina Muntenescu who blogs about spans and the like. (Emphasis in the following quote is mine.)

We need to draw a drawable together with the text. We can implement a custom ReplacementSpan to draw the background and the text ourselves. However ReplacementSpans cannot flow into the next line, therefore we will not be able to support a multi-line background. They would rather look like Chip, the Material Design component, where every element must fit on a single line.

I think that this is the flowing issue that you are having. As a work-around, you can insert the newline yourself when the condition occurs. There is no way that I know of to tell the ImageSpan to wrap.