gpt4 book ai didi

android - 在中间修剪 TextView,保留结尾字符

转载 作者:太空宇宙 更新时间:2023-11-03 10:19:52 25 4
gpt4 key购买 nike

我正在努力解决 textview 重叠问题。我有两个并排的 TextView

asd1234 | september 1

如果左侧 TextView 附加了更多字符(“567”),则结果为

asd…23{lost chars} | september 1

期望的结果是

asd…567 | september 1

我的 textview 属性是

        android:ellipsize="middle"
android:maxLines="1"
android:scrollHorizontally="true"

有什么方法可以让它与属性一起使用,还是我必须以编程方式修剪字符串?正确的做法是什么?谢谢

编辑

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_dark"
android:orientation="horizontal">

<TextView
android:id="@+id/header"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/date"
android:layout_centerVertical="true"
android:maxLines="1"
android:textColor="@android:color/holo_blue_dark" />

<TextView
android:id="@+id/date"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:maxLines="1"
android:textColor="@android:color/holo_blue_dark" />

</RelativeLayout>

最佳答案

我对您的 xml 做了一些更改:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_dark"
android:orientation="horizontal" >

<TextView
android:id="@+id/header"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/date"
android:singleLine="true"
android:text="I have wrote some longestttt text over here for testing the ellipsize"
android:textColor="#fff"
android:ellipsize="middle"/>

<TextView
android:id="@+id/date"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:maxLines="1"
android:text="02-09-2014"
android:textColor="#fff" />

</RelativeLayout>

主要是,将maxLines = 1 更改为singleLine = true,这有所不同。直到那时我还没有得到正确的输出:

这给我的输出是:

enter image description here

希望这对您有所帮助。

关于android - 在中间修剪 TextView,保留结尾字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25592310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com