【问题标题】:Nexus 5 monospace font has different width for unicode circlesNexus 5 等宽字体对 unicode 圆圈有不同的宽度
【发布时间】:2016-01-18 12:47:00
【问题描述】:

在 Android 应用程序中,我将信用卡条目作为四个 EditText 字段。这些字段被配置为使用等宽字体。

当我输入数字时,每个 4 字符块的宽度总是相同的。

但是,为了掩盖已经输入的信用卡详细信息,我使用了 unicode 黑色圆圈字符“●”。事实证明,即使是等宽字体,“●●●●”的宽度也比“1111”宽!当我尝试支持不同的系统字体大小和屏幕大小时,这给我带来了问题。

有趣的是,在带有 Marshmallow 的 Nexus 5 或带有 KitKat 的三星手机上,我看不到这个问题!

我是否遗漏了什么,或者 Lollipop 上的默认 Android 等宽字体实际上不是等宽字体?

我的 XML:

       <LinearLayout
        android:id="@+id/card_number_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center">

        <EditText
            android:id="@+id/card_field_1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:hint="●●●●"
            android:typeface="monospace"
            android:inputType="number"
            android:focusable="true"
            android:maxLength="4">
        </EditText>

        ...
        </LinearLayout>

【问题讨论】:

  • 我在 Marshmallow 上注意到了类似的问题,线条绘制字符不是等宽的。这主要出现在我使用 Connectbot 并使用这些字符运行终端会话时;框和列不与文本对齐。这使某些屏幕无法使用;我可能会降级回 KitKat。
  • 在我的 Droid4 上运行 KitKat,没有问题。在我的 Nook HD+ 上运行 CyanogenMod 13 (Marshmallow) 等宽是不对的。我还检查了运行 Lollipop 的 Geekbox,同样的问题。我还尝试将旧版本的 DroidSansMono.ttf 加载到我的 Nook 上(来自 Android 源代码树 github.com/android/platform_frameworks_base/tree/master/data/…),但即使使用 KitKat 版本的字体也没有任何改变。似乎正在使用其他字体而不是 DroidSansMono.ttf。 /system/etc/fonts.xml 在您的 Nexus 5 上是什么样的?
  • 我发现在 KitKat 中画线字符来自 DroidSansFallback.ttf - 这个文件在我的 Marshmallow 版本中完全不存在。此外,github 上最新版本的 DroidSansFallback 中缺少这些字符。 Noto* 系列中的一些其他字体被用于这些字符。如果我隐藏所有 Noto* 字体并安装 KitKat DroidSansFallback.ttf,那么我会正确排列线条绘图字符。

标签: android android-layout fonts font-size


【解决方案1】:

在我的 Marshmallow 版本中,这些图形字符来自 NotoSansSymbols-Regular-Subsetted.ttf,它们绝对不是等宽的。谷歌搞砸了。隐藏该文件并使用 Kitkat 中的 DroidSansFallback.ttf 让事情顺利进行。

我已经在这里提交了错误报告https://github.com/googlei18n/noto-fonts/issues/617

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-22
    • 2013-01-09
    • 2020-12-17
    • 1970-01-01
    • 2019-04-08
    • 1970-01-01
    • 2014-11-16
    • 2022-09-23
    相关资源
    最近更新 更多