【问题标题】:Limit the size of the textview horizontally水平限制文本视图的大小
【发布时间】:2012-02-24 23:45:16
【问题描述】:

我有这个文本视图

<TextView android:id="@+id/name"
          android:singleLine="true"
          android:layout_height="wrap_content"
          android:textColor="#ffffff" 
          android:textSize="16sp"  
          android:layout_width="fill_parent"/>

问题是如果文本更大然后 textview 可以显示它只是停止显示它看起来像这样|some unfinished tex|我想在最后有点这样用户会更清楚这是未完成,仅显示部分文本

我更喜欢这样的|Some unfinished te..|

如何实现?

【问题讨论】:

    标签: android layout textview android-ui android-gui


    【解决方案1】:

    您是否尝试过将android:ellipsize 参数设置为“结束”?

    【讨论】:

      【解决方案2】:

      每次我将它设置为 textview 时,我都会通过检查文本大小来使用 hack,并将这些点附加在文本的子字符串之后。我不知道这是不好的做法! :P

      【讨论】:

        【解决方案3】:

        你可以做这种类型;

        public String getChar(String inputstring){
        String substring;
        if(inputstring.length() >0 ){
        substring=inputstring.substring(int beginIndex, int endIndex);
        }
        StringBuilder sb=new StringBuilder(substring);
        sb.append("....");
        return sb.tostring();
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-09-26
          • 1970-01-01
          • 1970-01-01
          • 2013-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-12-10
          相关资源
          最近更新 更多