TextView中的ImageSpan对齐 [英] ImageSpan alignment in TextView

查看:63
本文介绍了TextView中的ImageSpan对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 TextView ,它利用了 android:lineSpacingMultiplier 属性来增加行之间的间距,除了我添加 ImageSpan时,效果还不错到文本.

I have a TextView which makes use of the android:lineSpacingMultiplier attribute to increase the spacing between lines, which works fine except for when I add an ImageSpan to the text.

这将使图像与行之间的空间的底部对齐,而不是与文本的基线对齐(这是我创建时指定的).

This causes the image to be aligned to the bottom of the space between lines, not the baseline of the text (as is specified when I create it).

我尝试使用 android:lineSpacingExtra 属性,但取得了一些成功,图像的位置仍然低于应有的水平,但幅度不大.是否有另一种方法可以增加行之间的间距而又不会弄乱 ImageSpan 的垂直对齐方式?

I tried using the android:lineSpacingExtra attribute, with some success, the image was still positioned lower than it should be, but not as much. Is there an alternate way of increasing the space between lines without messing up the vertical alignment of the ImageSpan?

推荐答案

构造ImageSpan时,可以指定垂直对齐方式,即 ImageSpan.ALIGN_BOTTOM ImageSpan.ALIGN_BASELINE .我相信ImageSpan默认使用 ALIGN_BOTTOM ,因此请尝试使用允许您指定 ALIGN_BASELINE 的构造函数.

When you construct the ImageSpan, you can specify a vertical alignment, one of ImageSpan.ALIGN_BOTTOM or ImageSpan.ALIGN_BASELINE. I believe ImageSpan uses ALIGN_BOTTOM by default, so try a constructor that allows you to specify ALIGN_BASELINE.

这篇关于TextView中的ImageSpan对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆