[英]How can I set multiline TextView Ellipsis properly in LinearLayout
I have such a layout hierarchy as following: 我的布局层次结构如下:
<LinearLayout
android:id="@+id/wrapper"
android:layout_width="50dp"
android:layout_height="63dp"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:background="#f00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title"
/>
<TextView
android:id="@+id/detail"
android:background="#0f0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="afasdfasdfasfasdfasfdasfasdfasfasdfsadfasfasdfasdfasdf"
/>
</LinearLayout>
The result view is like this: 结果视图如下所示:
The wrapper LinearLayout's height is going to be dynamically changed.So it is not fixed to 63dp.The fact is that the detail is being cut which doesn't satisfy my need.What I want is that the last complete visible line is changed to "XXX...".Like this: 包装器LinearLayout的高度将动态更改。因此它的高度不固定为63dp。事实是,细节被剪切,这不能满足我的需要。我想要的是最后一个完整的可见行更改为“ XXX ...”。就像这样:
From my code,I will change LinearLayout's height dynamically. 从我的代码中,我将动态更改LinearLayout的高度。
LinearLayout wrapper = (LinearLayout)findViewById(R.id.wrapper);
wrapper.getLayoutParams().height = // dynamical height;
Your best bet is to utilize the maxLines
and ellipsize
attributes. 最好的选择是利用
maxLines
和ellipsize
属性。
<TextView
android:id="@+id/detail"
android:background="#0f0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:ellipsize="end"
android:text="afasdfasdfasfasdfasfdasfasdfasfasdfsadfasfasdfasdfasdf"
/>
将android:layout_height="63dp"
更改为android:layout_height="wrap_content"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.