简体   繁体   English

如何在Android的换行符处剪切(删除)复选框文本?

[英]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. 我正在创建一个Android应用程序,其中的一部分包括按组存储联系人。 In the image below you can see the group "CEOs" and the group members that belong to it. 在下图中,您可以看到“ CEOs”组和所属的组成员。

在此处输入图片说明

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. 起初,我硬编码应在28个字符后删除文本,但这显然不是一个好的解决方案。

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:- 尝试使用文本视图的ellipsize和max Lines属性作为:

<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. 如果超过当前行,则ellipsize将在文本末尾设置点(...)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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