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

在运行应用程序时,提示是不可见的。我发现我应该使椭圆值的TextView是开始:

<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在字典里找不到。谁能给我解释一下椭圆大小属性能给我们带来什么好处?开始,结束,中间的区别是什么?


当前回答

如上所述,如果没有足够的文本空间(由于布局大小或设置限制),ellpsize将添加…点到它。

这里有一个例子: 顶部:带有椭圆大小(这里设置为'end') 底部:没有

其他回答

如上所述,如果没有足够的文本空间(由于布局大小或设置限制),ellpsize将添加…点到它。

这里有一个例子: 顶部:带有椭圆大小(这里设置为'end') 底部:没有

将此属性设置为EditText。Ellipsize与禁用EditText一起工作

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

还是setKeyListener(空);

文本:

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

假设上面是你的文本,如果你使用ellipsize的start属性,它会像这样

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

带有end属性

 This is my first android application and
 I am trying to make a funny game,...

省略号是连续三个句号。

当TextView不能展开显示其所有文本时,它将使用省略号。属性ellipsized在必要时设置三个点的位置。

下面是一个例子,关于ellipsize如何工作,而不使用已弃用的android:singleLine="true"在一个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" />

记住,如果你有一个文本应该在单行中,然后将maxLines更改为1。