Android Ellipsize功能无法正确显示

时间:2015-11-24 11:27:13

标签: android android-layout

我已经看到了一些关于同一问题的问题," Ellipsize没有工作"。这些解决方案都不适合我。实际上,textview的设置如下:

Ellipsize not working for textView inside custom listView中所示。

<com.neopixl.pixlui.components.textview.TextView
    android:id="@+id/wifispot_info_address"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginLeft="15dp"
    android:layout_weight="0.5"
    android:gravity="center_vertical"
    android:text="@string/default_string"
    android:textColor="@color/black"
    android:textSize="16sp"
    pixlui:typeface="NeutraText-Book.otf"
    android:ellipsize="end"
    android:scrollHorizontally="true"
    android:singleLine="true"/>

此外,我尝试在片段代码中设置属性,如Ellipsize is not working所示:

spotAddress = (TextView) view.findViewById(R.id.wifispot_info_address);
spotAddress.setEllipsize(TextUtils.TruncateAt.END);

The better results show the "address" cutted without the ellipsize and the rest is "displayed" in another line.

从这个xml开始,我该怎么办?

<com.neopixl.pixlui.components.textview.TextView
    android:id="@+id/wifispot_info_address"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginLeft="15dp"
    android:layout_weight="0.5"
    android:gravity="center_vertical"
    android:text="@string/default_string"
    android:textColor="@color/black"
    android:textSize="16sp"
    pixlui:typeface="NeutraText-Book.otf"
    android:ellipsize="end"
    android:scrollHorizontally="true"
    android:singleLine="true"/>

1 个答案:

答案 0 :(得分:0)

您可以添加android:maxLines="1"

  

使TextView最多只有这么多行。当用在   可编辑文本,inputType属性的值必须与   要应用的maxLines属性的textMultiLine标志。

<com.neopixl.pixlui.components.textview.TextView
android:id="@+id/wifispot_info_address"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_weight="0.5"
android:gravity="center_vertical"
android:text="@string/default_string"
android:textColor="@color/black"
android:textSize="16sp"
pixlui:typeface="NeutraText-Book.otf"
android:ellipsize="end"
android:scrollHorizontally="true"
android:singleLine="true"
android:maxLines="1"/>