【发布时间】:2012-10-19 00:34:10
【问题描述】:
我有几个完全相同的TextViews 垂直对齐(左边距相同,左边距相同,左边位置相同)。它们可以有不同的文本大小,并且文本可以以不同的字母开头。问题是,虽然TextViews 是左对齐的,但其中的文本却不是。有可能实现这一目标吗?删除/分解每个第一个字母之前的额外空间?还是我应该寻找一些特定的字体?
下面的图片显示了这种情况。有三个TextViews 与左边对齐,但每个字母的开始点不同。 s 和 m 大小相同,但未对齐。 i 比较小,差距要大很多。
我所看到的:
我想要什么:
示例代码:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="m"
android:textColor="#88FF0000"
android:textSize="250dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="s"
android:textColor="#8800FF00"
android:textSize="250dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="220dp"
android:text="i"
android:textColor="#880000FF"
android:textSize="25dp" />
</RelativeLayout>
【问题讨论】:
-
我认为这对于 TextView 是不可能的。您可能可以使用来自
Paint.getTextWidths()的信息自己使用画布并绘制文本,但我不知道从中返回的宽度是否包括周围的空白(我猜它赢了'没有帮助)。 -
我相信 TextView 是可能的,它只需要一个 MonoSpaced 字体。
-
我试过
android:typeface="monospace"并没有帮助。
标签: android text vertical-alignment