Android等宽字体实际上是固定大小的吗? [英] Are Android monospace fonts actually fixed size?

查看:147
本文介绍了Android等宽字体实际上是固定大小的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为游戏使用Android Monospace字体,但发现该字体的行为不符合预期。游戏依靠头号人物,下面的下划线彼此并列,作为解决密码的线索。但是,当单词非常靠近 TextView 的边缘时(如图像中的第5行所示),文本的蓝色行将移至下一行,从而导致提示和答案不同步。

I am using the Android Monospace font for my game and have found that the font does not behave as expected. The game relies on the top characters and the underscores below being lined up with each other as clues to solve the cryptogram. However when the word is very close to the edge of the TextView as can be seen on the 5th line shown in the image the blue line of text goes onto the next line causing the clues and answers to be out of sync.

我正在使用 TextView.setTypeface(Typeface.MONOSPACE)两行(嗯...非常紧密地基于它的字体-这个问题也发生在MONOSPACE上。)

I'm using TextView.setTypeface(Typeface.MONOSPACE) for both lines (well... a font very closely based on it - the issue happens with MONOSPACE as well though).

任何想法都可能是什么原因以及如何导致修复它?

Any ideas what could be causing this and how to fix it?

推荐答案

因此,事实证明, TextView 文本换行的算法并不简单-下一个单词是否适合此行->如果不放,

So it turns out that the algorithm for TextView text wrapping is NOT as simple as - does the next word fit on this line --> if not put it on the next line.

稍后在该屏幕截图中,黑色和蓝色的文本有所不同(一个显示引号的作者,另一个显示d不会)。看来 TextView 试图使行最小化,完成后它使宽度最小化。鉴于屏幕快照中的两个文本大约有1行不同,因此可以重新排列结尾的小字,以减小 TextView 的宽度。这就是导致问题的原因-字体(据我所知)实际上是完全等宽的。

Later in that screenshot the texts in black and blue differ (one shows the author of the quote the other does not). It seems the TextViewis trying to minimise lines and after this has been accomplished it minimises the width. Given the two texts in the screenshot are ~1 line of text different the small words at the end can be rearranged to make the TextView's width smaller. This is what causes the issues - the font is (as far as I can tell) in fact perfectly monospace.

我想此问题的正确解决方案是扩展 TextView 并进行自定义 onDraw()来解决该问题。对我来说,使两个文本显示完全相同的单词就足够了(但是其中一个通过替代密码传递)。

This proper solution to this problem I suppose is to extend TextView and make a custom onDraw() to deal with the problem. For me, it was sufficient to make the two texts show exactly the same words (but with one being passed through a substitution cipher).

这篇关于Android等宽字体实际上是固定大小的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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