日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android代码设置maxlength,android-使用maxLength使用3个点结束TextView

發布時間:2024/1/1 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android代码设置maxlength,android-使用maxLength使用3个点结束TextView 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

android-使用maxLength使用3個點結束TextView

我的布局中有一個TextView,它是layout_width中的wrap_content。 最多限制為15個字符,因此我正在使用maxLength。

我需要以3個點(...)結束此TextView,并且僅當我使用dp給layout_width提供固定大小時才會發生,這是我不想做的事情。

我知道可以通過代碼做到這一點,并在第15個字符后剪切字符串,然后添加3個點,但是我更喜歡通過XML來實現。

知道如何以3個點結束文本并保留wrap_content嗎?

android:id="@+id/inbox_contactName"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:lines="1"

android:maxLines="1"

android:ellipsize="end"

android:singleLine="true"

android:maxLength="15"

android:textColor="#0670b4"

android:textSize="16sp" />

Yaniv asked 2020-02-04T07:39:38Z

10個解決方案

68 votes

這將解決您的問題,在XML代碼中使用singleLine屬性

android:ellipsize="end"

android:maxEms="15"

android:singleLine="true"

編輯:singleLine已棄用。 請改用maxlines="1"。

Kirk answered 2020-02-04T07:39:58Z

17 votes

我從評論中收集到@Yaniv已經使用代碼解決了它-但這是正確的方法(使用xml)。 可能會幫助登陸這里的其他用戶。 技巧是同時使用toleftof和torightof。

...

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:singleLine="true"

android:layout_toRightOf="@id/some_element1"

android:layout_toLeftOf="@id/some_element2"/>

...

Ravi answered 2020-02-04T07:40:18Z

11 votes

盡管可以定義Maximum EMS,但不能同時使用maxLength和Ellipsize,請參見下面的示例

android:id="@+id/tv_hist_source_lang"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:ellipsize="end"

android:maxEms="8"

android:maxLines="1"

android:text="TextView"

android:textAppearance="?android:attr/textAppearanceMedium" />

AZ_ answered 2020-02-04T07:40:38Z

10 votes

您可以使用

android:maxWidth="100dp"

android:maxLines="1"

android:ellipsize="end"

只有這對我有用。

Zhou Hongbo answered 2020-02-04T07:41:02Z

5 votes

使用這個android:ellipsize="end"

Mahmoud Hashim answered 2020-02-04T07:41:22Z

4 votes

最簡單的方法之一是添加Right Padding + Ellipsize

android:id="@+id/txtvw_contentcell_subhead"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Polem sampler, Lorem Ipsum golep tolem burop yemit noski"

android:ellipsize="end"

android:maxLines="1"

android:textColor="@color/caption_black_color"

android:textSize="@dimen/caption_size"

android:paddingRight="40dp"/>

這是帶有字符數限制的示例字幕文本。

Enzokie answered 2020-02-04T07:41:46Z

0 votes

我需要使用單選按鈕執行此操作,并且我想將大小限制為一行。 當我使用Android:singleline="true"時,單選按鈕的選中圓圈消失了。 這是最終起作用的代碼:

android:ellipsize="end"

android:maxLines="1"

無需設置em。 這在TextView和其他UI組件中也可能起作用。 希望這對某人有幫助。

Micer answered 2020-02-04T07:42:11Z

0 votes

您可以修改長度大于20的String,以添加橢圓尺寸。

Horatio answered 2020-02-04T07:42:31Z

0 votes

非常重要:ellipsize = "end"僅在maxLength設置為大于一行字符數的值時才有效。如果您將TextView的末端對齊并開始到任何其他視圖,則可以使用wrap_content。

Benjamin Livinus answered 2020-02-04T07:42:52Z

-1 votes

從xml刪除行

android:lines="1"

android:maxLines="1"

Muhammad Aamir Ali answered 2020-02-04T07:43:12Z

總結

以上是生活随笔為你收集整理的android代码设置maxlength,android-使用maxLength使用3个点结束TextView的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。