我有一个TextView,我想限制它的字符。实际上,我可以这样做,但我正在寻找的事情是如何在字符串的末尾添加三个点(…)。这一个显示文本已经继续。这是我的XML,但没有点,尽管它限制了我的文本。

<TextView 
        android:id                      = "@+id/tvFixture"
        android:layout_width            = "wrap_content"
        android:layout_height           = "wrap_content"
        android:layout_toLeftOf         = "@id/ivFixture_Guest"
        android:text                    = "@string/test_06"
        android:lines                   = "1"
        android:ems                     = "3"
        android:gravity                 = "right"
        style                           = "@style/simpletopic.black" 
        android:ellipsize="end"/>

当前回答

我认为你想限制宽度为一行,而不是限制它的字符?由于singleLine已弃用,您可以尝试使用以下组合:

android:maxLines="1"
android:scrollHorizontally="true"
android:ellipsize="end"

其他回答

为了使用android:ellipsize属性,你必须限制TextView的布局宽度,这样文本就超出了TextView视图的边界。

所以,android:layout_width属性在这里起着关键作用,相应地设置它。

一个例子可以是:

<TextView        
    android:layout_width="120dp"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:text="This is a very long text to be displayed"
    android:textSize="12sp"
    android:maxLines="1"            
     />

现在,这里如果文本在android:text="这是一个很长的文本要显示"从TextView与android:layout_width="120dp", android:ellipsize="end"将截断文本和地方…(3点)在它后面。这太长了……将显示在TextView中。

        <TextView
            android:id="@+id/product_description"
            android:layout_width="165dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:paddingLeft="12dp"
            android:paddingRight="12dp"
            android:text="Pack of 4 summer printed pajama"
            android:textColor="#d2131c"
            android:textSize="12sp"
            android:maxLines="2"
            android:ellipsize="end"/>

简单的三点

android:layout_width="100dp" <!--your dp or match_parent or 0dp>
android:maxLines="2" <!--count your line>
android:ellipsize="end"

在你的课文中加上这两行

android:ellipsize="end"
android:singleLine="true"

你可以用XML写这一行,在这里你取textview:

android:singleLine="true"