更改TextView的文字字距或间距? [英] Change text kerning or spacing in TextView?

查看:518
本文介绍了更改TextView的文字字距或间距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,其中需要一个TextView的字母被间隔开远一点。不幸的是,最让我找到的资源似乎在说这个不能做 - 至少不容易

I have a requirement where the letters in a TextView need to be spaced a little farther apart. Unfortunately, most of the resources I find seem to say this cannot be done--at least not easily.

到目前为止,表观的解决方案是: 1.添加空格在String--ABC的字符,而不是ABC之间。当然,如果仅需要稍微更多的空间不工作。 2.改变textScale,但影响的字母的大小,不只是字母之间的间隔 3.使用字体类,但不可用,直到蜂窝(我需要的东西姜饼兼容),它一直pcated在软糖德$ P $,所以这不是一个很好的选择。 4.找到不同的字距字体,但是这不是实际的,如果客户希望使用相同的字体。 5.覆盖OnDraw中的视图,画人物的帆布一个字符时,手动指定正是每一个字符应绘制。

So far, the apparent solutions are: 1. Add spaces in between the characters in the String-- "A B C" instead of "ABC". Of course, that doesn't work if only a LITTLE more space is needed. 2. Change textScale, but that affects the size of the letters, not just the spacing between letters 3. Use the Font class, but that isn't available until Honeycomb (I need something Gingerbread compatible) and it has been deprecated in JellyBean, so that's not a good option. 4. Find a font with different kerning, but that's not practical if clients want to use the same font. 5. Override onDraw for a View, drawing characters to the Canvas one character at a time, manually specifying exactly where each character should be drawn.

有我丢失的东西?好像应该有一个更好的办法。我看到TextAttribute.KERNING和TextAttribute.TRACKING ......好像这些应该能够很容易地使用,但我无法弄清楚如何。

Is there something I'm missing? It seems like there should be a better way. I see TextAttribute.KERNING and TextAttribute.TRACKING... it seems like those should be able to be used easily, but I can't figure out how.

什么是改变一个TextView字母之间的间距最好的方法是什么?

What's the best way to change the spacing between letters in a TextView?

推荐答案

我找到解决的办法是搭配你所描述的解决方案1和2。字母之间,比只改变空间的TextScaleX添加空格,所以你把其他人物一样。我建立了一个扩展的TextView ,并允许您定义的字母间距的自定义类。其他一切都是自动=)

The solution I found is to mix the solutions 1 and 2 that you described. Adding spaces between letters and than changing the TextScaleX only of the spaces, so you keep other characters the same. I built a custom class that extends TextView and allows you to define the letter spacing. Everything else is automatic =)

我贴在班级这个其他回答

希望有所帮助^^

这篇关于更改TextView的文字字距或间距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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