Android TextViews 中的等宽表格数字 [英] Monospace tabular numbers in Android TextViews

查看:37
本文介绍了Android TextViews 中的等宽表格数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义字体,默认情况下具有可变宽度的数字字形,我想在 Android TextView 中使用字体的等宽表格数字功能,以便数字垂直对齐.

I have a custom font which has variable-width numeric glyphs by default, and I would like to use the font's monospace tabular numbers feature in an Android TextView so that numbers align vertically.

也就是说,像这样改变:

That is, change something like this:

像这样:

推荐答案

要选择字体的表格编号功能,请使用 TextViewfontFeatureSettingstnum:

To select a font's tabular number feature, use TextView's fontFeatureSettings with tnum:

<TextView
    ...
    android:fontFeatureSettings="tnum"
    android:text="1111.11\n2222.22"
    />

需要 API 级别 21.

Requires API level 21.

这篇关于Android TextViews 中的等宽表格数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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