如何截断TextView的,然后在Android中加省略号 [英] How to truncate TextView, and then add ellipsis in Android

查看:215
本文介绍了如何截断TextView的,然后在Android中加省略号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读了几这里类似的担忧其他线程,但没有他们的答案似乎为我工作。

I have read a few of the other threads here with similar concerns, but none of their answers seemed to work for me.

无法获得省略号在Android上工作

<一个href=\"http://stackoverflow.com/questions/3769105/android-something-better-than-androidellipsize-end-to-add-to-truncated\">Android:东西比Android更好:ellipsize =&QUOT;末&QUOT;加入&QUOT; ...&QUOT;以截断长字符串?

我有两个元素,一个文本视图和图像视图相对布局。我需要的文本视图是1号线和截断有关图像视图5SP短,适用省略号到文本的末尾。

I have a Relative Layout with 2 elements, a text view and an image view. I need the text view to be 1 line and to truncate about 5sp short of the image view and apply ellipsis to the end of the text.

<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>

在上面的code,我试图申请留下来的图片浏览,迫使文本视图其留下的尽可能多的SP,因为我把在空白处截断保证金。

In the above code, I was attempting to apply a margin left to the Image View to force the text view to its left to truncate by as many sp as I put in the margin.

在code以上会截断文本视图一行,并添加(...),但只有该行的结尾;该ImageView的它,不论是正确的,不管我适用于它的任何保证金。图像视图显示的文本上方。我想这可能是因为他们在一个相对布局之中。

The code above would truncate the text view to a single line and add (...) but only to the end of that line; irrespective of the ImageView to it's right, regardless of whatever margin I apply to it. The Image View appears above the text. I figured this may be due to them being in a relative layout.

在搞清楚如何使文本视图尊重图像视图占用保证金/空间将大大AP preciated任何帮助。

Any help in figuring out how to make the text view respect the margin/space taken up by the image view would be greatly appreciated.

推荐答案

我相信你想要做的是第一名图像预览(利润),然后将文本对齐到左边框和放置到leftOf图像

I believe what you want to do is to first place the image view (with margins) and then set the text to align to the left border and to be placed to the leftOf the image.

这篇关于如何截断TextView的,然后在Android中加省略号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆