android imagespan不支持自动下一行

发布于 2025-01-10 01:02:20 字数 366 浏览 1 评论 0原文

android ImageSpan,在textview中,当最后一个位置显示大图像很小,但我的图像很大,我想要ImageSpan自动 下一行。我尝试重载大小方法并更改大小 等于textview宽度,但不能解决

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

我无法更改内容的问题,我希望使用imagespan实现auto 下一行函数

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泅渡 2025-01-17 01:02:20

ImageSpan 是 ReplacementSpan 的间接子类。显然,ReplacementSpan(因此是 ImageSpan)无法做到换行。这里引用了一篇文章 绘制圆角背景关于文本,作者:Florina Muntenescu,她在博客中介绍了跨度等内容。 (以下引用中的强调是我的。)

我们需要将一个可绘制对象与文本一起绘制。我们可以实现自定义 ReplacementSpan 来自己绘制背景和文本。 但是 ReplacementSpans 无法流入下一行,因此我们将无法支持多行背景。它们宁愿看起来像 Chip,Material Design 组件,其中每个元素都必须放在一行上。

我认为这是您遇到的流动问题。作为解决方法,您可以在出现这种情况时自行插入换行符。据我所知,没有办法告诉 ImageSpan 换行。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文