java - 如何更改单词之间的距离?
问题描述
如何使用这些方法更改 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)
,您可以添加一个参数来更改单词之间的距离。
解决方案
有不同宽度的不同类型的空间:
- →</kbd>←</kbd> - Tag Space
- →</kbd> <kbd>←</kbd> - Hair Space
- →</kbd> <kbd>←</kbd> - Thin Space
- →</kbd> ←</kbd> - Regular Space
- →</kbd> ←</kbd> - No-Break Space
- →</kbd> <kbd>←</kbd> - Punctuation Space
- →</kbd> <kbd>←</kbd> - Figure Space
- →</kbd> <kbd>←</kbd> - En Space
- →</kbd> <kbd>←</kbd> - Em Space
推荐阅读
- javascript - Stacked bars chart not rendering on mobile
- android - 如何每次使用 gradle 制作方面编织 kotlin 代码
- apache-kafka - Produce 调用配置了 IAsyncSerializer 值序列化器,但使用 Avro 序列化器时需要 ISerializer
- jquery - 用jquery替换html元素不起作用
- wpf - 禁用列表框的 Powershell WPF 样式模板
- r - For 循环在循环中失败 grobs [[i]] 中的错误:下标超出范围
- rust - 为什么将 tokio_postgres::Transaction 作为参考传递要求指示匿名生命周期?
- amazon-web-services - 使用 AWS 进入我的 CodePipeline 的“部署”阶段时出现持续错误
- rust - 为什么我会收到错误“const fn 中的函数指针不稳定”,但是当包装在新类型中时它会消失?
- r - 使用 R 在 Power BI 中渲染动态 geom_hlines 时遇到问题