Android:以编程方式计算Listview字体指标

时间:2013-07-15 21:33:06

标签: android fontmetrics

我有一个字符串,我需要截断字符串,使其适合ListView中的一行。

有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:1)

您需要在列表项行文件的XML中指定。

这些是您需要在TextView上使用的属性;

android:singleLine="true"
android:maxLength="someLengthofCharacters(int)"
android:ellipsize="end"  //if you want an ellipse to be appended to the end of your String

编辑:尝试使用此方法以编程方式设置TextView的最大字符长度

TextView tv = new TextView(this);
int maxLength = 10;
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
tv.setFilters(fArray)

并使用

将单行设置为true
TextView.setSingleLine or TextView.setLines(1)
相关问题