美文网首页
TextView多行文字缩略显示与收起功能

TextView多行文字缩略显示与收起功能

作者: APP福星高照 | 来源:发表于2020-03-04 15:56 被阅读0次

TextView多行文字缩略显示与收起功能。先看效果

WeChat54bfb85f200ad69cf06be951c5fd901e.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("这是一个很长很长的文字这是一个很长很长的文字这是一个很长很长的文字这是一个很长很长的文");

相关文章

网友评论

      本文标题:TextView多行文字缩略显示与收起功能

      本文链接:https://www.haomeiwen.com/subject/vetblhtx.html