【发布时间】:2013-07-15 21:33:06
【问题描述】:
我有一个字符串,我需要截断该字符串以使其适合 ListView 中的一行。
谁能指出我正确的方向?
【问题讨论】:
标签: android fontmetrics
我有一个字符串,我需要截断该字符串以使其适合 ListView 中的一行。
谁能指出我正确的方向?
【问题讨论】:
标签: android fontmetrics
您需要在列表项行文件的 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)
【讨论】: