SpannableString 在另一个单词之间的顶部和底部有空格

大家好?所以我有一个 TextView,我有一个 Word of value,我必须只在值上设置一些样式,比如

问题是,我需要在 textview 中此值的顶部和底部放置空间,以便与 String 的其余部分稍微分开。

我需要让它这样

SpannableString 在另一个单词之间的顶部和底部有空格

我现在的代码是这样的

<script type="text/discourse-plugin" version="0.8">
    api.decorateWidget('post:after',helper => {
        let post = helper.getModel();
        if (post.get('post_number') % 3 === 0) { // after every 3 posts
            return helper.rawHtml(`
<div class="lead_static_wrapper"><p>Label</p>
<div class="proper-ad-unit">
<div id="pr-ad-nr_main_1">


<script>propertag.cmd.push(function() { proper_display('nr_main_1'); });</script>


</div>
</div>
</div>
            `);
        }
    });
</script>

我可以把值格式化,但我需要的顶部和底部的空间我不能放。

yyb4051 回答:SpannableString 在另一个单词之间的顶部和底部有空格

我可以按照这个答案解决它,我做了一些调整并且工作正常。 Using LineHeightSpan

private class MarginTopBottomSpan(
    private val topMargin: Int,private val bottomMargin: Int
) : LineHeightSpan {

    override fun chooseHeight(
        text: CharSequence,start: Int,end: Int,spanstartv: Int,v: Int,fm: FontMetricsInt
    ) {
        fm.bottom += bottomMargin
        fm.descent += bottomMargin
        fm.top += topMargin * VALUE_NEGATIVE
        fm.ascent += topMargin * VALUE_NEGATIVE
    }

    companion object {

        private const val VALUE_NEGATIVE = -1
    }
}
本文链接:https://www.f2er.com/13153.html

大家都在问