TextView多行文字缩略显示与收起功能。先看效果
![](https://img.haomeiwen.com/i8635142/f92b2e84f6764880.png)
使用了一个第三方的ExpandableTextView
https://gitee.com/fxgz/ExpandableTextView1
使用方法很简单
1、导入
implementation 'cn.carbs.android:ExpandableTextView:1.0.3'
2、加入xml
<cn.carbs.android.expandabletextview.library.ExpandableTextView
android:id="@+id/expandTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#333333"
android:textSize="14sp"
app:etv_MaxLinesOnShrink="3"
app:etv_EllipsisHint="..."
app:etv_ToExpandHint="显示全部"
app:etv_ToExpandHintColor="@color/colorAccent"
app:etv_ToShrinkHintColor="@color/colorAccent"
/>
3、java代码设置text
ExpandableTextView exTv = holder.itemView.findViewById(R.id.expandTextView);
exTv.setText("这是一个很长很长的文字这是一个很长很长的文字这是一个很长很长的文字这是一个很长很长的文");
网友评论