【问题标题】:Android: Programmatically calculate Listview Font MetricsAndroid:以编程方式计算 Listview 字体指标
【发布时间】:2013-07-15 21:33:06
【问题描述】:

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

谁能指出我正确的方向?

【问题讨论】:

    标签: android fontmetrics


    【解决方案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)
    

    【讨论】:

    • 经过思考:您使用的是自定义列表视图和适配器吗?
    猜你喜欢
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 2021-11-20
    • 2011-01-28
    相关资源
    最近更新 更多