238

我在EditText布局中添加了一个,并添加了一个提示,并使其水平居中。

运行应用程序时,提示是不可见的。我发现我应该使ellipsize价值TextView成为start

<EditText
    android:id="@+id/number1EditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="start"
    android:ems="10"
    android:gravity="center_horizontal"
    android:hint="@string/hint1" />

在 Android 文档中,我读到:

如果设置,会使长于视图宽度的单词变成
椭圆而不是在中间断开。

问题是ellipsize在字典中找不到。谁能向我解释我们可以通过ellipsize属性获得什么好处?start, end,之间有什么区别middle

4

9 回答 9

453
于 2012-11-09T18:45:50.207 回答
78

In my experience, Ellipsis works only if the below two attributes are set.

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

for the width of TextView, wrap_content or match_parent should both be good.

于 2014-02-04T17:22:20.733 回答
19

android:ellipsize added in API Level 1. An ellipsis is three periods in a row. (...) .

In your .xml

 <TextView
       ....
       android:text="Hi I am Amiyo, you can see how to ellipse works."
       android:ellipsize = "end" />

At this point, the ellipsis will not display yet as a TextView is set to automatically expand on default when new text is entered. You will need to limit TextView in some way. Do this, you can use either add to your TextView a scrollHorizontally, minLines, or maxLines to have the ellipsis display.

To make the ellipse:

    at the end: this is how it would.   
    use: android:ellipsize = "end"

And

 in the middle:
 use: android:ellipsize = "middle"

And

 at the start:
 use: android:ellipsize = "start"

And

 to have no ellipse
 use: android:ellipsize = "none"

Note Please :

Do not use android:singeLine = "true", it is deprecated.
android:maxLines = "1" will not display the three dots (...)
android:lines = "1" will not display the three dots (...)

For more details you can visit here

于 2015-04-06T05:36:51.147 回答
10

An ellipsis is three periods in a row...

The TextView will use an ellipsis when it cannot expand to show all of its text. The attribute ellipsized sets the position of the three dots if it is necessary.

于 2012-11-09T18:48:24.630 回答
5

Text:

 This is my first android application and
 I am trying to make a funny game,
 It seems android is really very easy to play.

Suppose above is your text and if you are using ellipsize's start attribute it will seen like this

This is my first android application and
...t seems android is really very easy to play.

with end attribute

 This is my first android application and
 I am trying to make a funny game,...
于 2012-11-09T19:06:23.043 回答
4

Here is an example on how ellipsize works without using deprecated android:singleLine="true" in a ConstraintLayout:

<TextView
   android:layout_width="0dp"
   android:layout_height="wrap_content"
   android:textSize="13sp"
   android:ellipsize="end"
   android:maxLines="2"
   app:layout_constraintEnd_toEndOf="parent"
   app:layout_constraintStart_toStartOf="parent"
   tools:text="long long long long long long text text text" />

remember if you have a text that is supposed to be in a single line, then change the maxLines to 1.

于 2019-03-07T01:44:59.793 回答
1

Note: your text must be larger than the container box for the following to marquee:

 android:ellipsize="marquee"    
于 2013-12-27T15:16:33.037 回答
1

Set this property to EditText. Ellipsize is working with disable EditText

android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
android:singleLine="true"
android:editable="false"

or setKeyListener(null);

于 2013-12-31T12:34:18.507 回答
0

Use ellipsize when you have fixed width, then it will automatically truncate the text & show the ellipsis at end,

it Won't work if you set layout_width as wrap_content & match_parent.

android:width="40dp"
android:ellipsize="end"
android:singleLine="true"
于 2020-03-25T04:58:23.737 回答