有时候我们会遇到这样的问题,一个大字符串写到TextView里面,根本写不下,但是该字符串并不是固定的,所以我们不知道需要定多长的TextView
所以对于过长的字符串我们最后以省略号代替。如下所示:
TextView只显示一行,并且对于超出TextView宽度的部分以省略号结束。
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/HelloWorld"
android:ellipsize="end"
android:singleLine="true"
/>
其实省略号不只可以放在结尾部分,也可以放在前面,中间等,如下:
android:ellipsize="start" 省略号在开头
android:ellipsize="middle" 省略号在中间
android:ellipsize="end" 省略号在结尾
android:ellipsize="marquee" 跑马灯显示
2016.5.29 北京 炎热的午后~太阳光很强烈