首页 > 解决方案 > 如何更改单词之间的距离?

问题描述

如何使用这些方法更改 Android Studio 中字符串中单词之间的距离?我需要距离大约是标准空间大小的一半。

val spanMsg = SpannableStringBuilder()
    msg?.forEachIndexed { i, char ->//replacing non-printable characters
                                    //with their code and highlighting
        if (char.isControlChar()) {//checking for non-printable characters
            spanMsg.appendWithSpan(" ", RelativeSizeSpan(BLOCKS_INDENT))
            for(x in toHex(Character.toString(char)
                                    .toByteArray(StandardCharsets.UTF_16BE))!!) {
                spanMsg.appendWithSpan(
                        x,
                        ForegroundColorSpan(Color.WHITE),
                        BackgroundColorSpan(Color.BLACK)
                )
            }
fun SpannableStringBuilder.appendWithSpan(text: CharSequence, vararg what: Any) {
this.append(text)
what.forEach {
    this.setSpan(
            it,
            this.length - text.length,
            this.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
    )
}

据我了解,在 之后BackgroundColorSpan(Color.BLACK),您可以添加一个参数来更改单词之间的距离。

标签: javastringkotlincharwhitespace

解决方案


有不同宽度的不同类型的空间


另请参阅:是否有一个 ASCII 箭头可以与画框字符无缝匹配?


推荐阅读