简体   繁体   中英

How to cut off (delete) checkbox-text at newline in Android?

I am creating an Android application where part of it consists of storing contacts in groups. In the image below you can see the group "CEOs" and the group members that belong to it.

在此处输入图片说明

However, I would like to not show this whole text, but only the part that can fit on the line (without creating a newline). So, in this case everything after "Mark" would have to be deleted.

I am struggling to find a way to make this relative. At first I hard-coded that the text should be deleted after 28 characters, but this is obviously not a good solution.

When I tried to split the text on the newline and delete the last part, this did not work either, as apparently the newline I see on the layout is not "recorded" in the checkbox text.

Does anyone have an idea on how to solve this?

Try to use ellipsize and max Lines property of the text view as:-

<TextView
    android:id="@+id/textViewPostTitle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/TextAppearance.AppCompat.Title"
    android:ellipsize="end"
    android:maxLines="1"
    android:text="This is our title"/>

ellipsize will set dots (...) at the end of the text if it is exceeding the current line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM