我读过这里的一些其他线程也有类似的担忧,但他们的答案似乎都不适合我。
无法在 Android 上使用省略号 https://stackoverflow.com/questions/1698881/cant-get-ellipsis-to-work-on-android
Android:比 android:ellipsize="end" 更好的东西可以将“...”添加到截断的长字符串中? https://stackoverflow.com/questions/3769105/android-something-better-than-androidellipsize-end-to-add-to-truncated
我有一个包含 2 个元素的相对布局,一个文本视图和一个图像视图。我需要文本视图为 1 行,并截断图像视图的大约 5sp,并将省略号应用于文本末尾。
<RelativeLayout
android:id="@+id/title_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5sp">
<TextView
android:id="@+id/"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="10sp"
android:textColor="#FFFFFF"
android:text="title"
android:maxLines="1"
android:ellipsize="end"/>
<ImageView
android:id="@+id/"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5sp"
android:layout_marginLeft="5sp"
android:background="@drawable/home"/>
</RelativeLayout>
在上面的代码中,我尝试向图像视图应用左侧边距,以强制左侧的文本视图按照我在边距中放置的 sp 值进行截断。
上面的代码会将文本视图截断为一行并添加 (...) 但仅添加到该行的末尾;无论 ImageView 是否正确,无论我对其应用什么边距。图像视图出现在文本上方。我认为这可能是由于它们处于相对布局中。
任何帮助弄清楚如何使文本视图尊重图像视图占用的边距/空间的帮助将不胜感激。
我相信您想要做的是首先放置图像视图(带边距),然后将文本设置为与左边框对齐并放置在图像的左侧。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)