将Textview内容保留在1行并防止包装

时间:2021-04-13 22:20:21

I would like to have a text displayed on a Android widget (remote views) not wrap over its text to the next line, if the text is longer than the Textview's width. Instead of that, I would like to have the Textview cut any extra text. I have tried many things without success. Is there an easy solution to this?

如果文本长度超过Textview的宽度,我希望Android小部件(远程视图)上显示的文本不会将其文本换行到下一行。而不是那样,我想让Textview剪切任何额外的文本。我尝试过许多事情都没有成功。这有一个简单的解决方案吗?

Here is the xml code for the TextView

这是TextView的xml代码

    <TextView
        android:id="@+id/txtInformation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp"
        android:maxWidth="220dp"
        android:lines="1"
        android:text="Long text long text long text long text"
        android:textSize="13sp" />

1 个解决方案

#1


5  

In your layout XML, use android:maxLines="1" or android:singleLine="true"

在你的布局XML中,使用android:maxLines =“1”或android:singleLine =“true”

#1


5  

In your layout XML, use android:maxLines="1" or android:singleLine="true"

在你的布局XML中,使用android:maxLines =“1”或android:singleLine =“true”