ExpandableTextView
仿微信朋友圈全文、收起的TextView,可在RecyclerView和ListView中使用,不会有错乱和空白问题,完全采用kotlin编写。
Install / Use
/learn @devzld/ExpandableTextViewREADME
ExpandableTextView
仿微信朋友圈全文、收起的TextView,可在RecyclerView和ListView中使用,不会有错乱和空白问题。
欢迎各位star和提issues!

使用方法
1、引入
在你项目module的build.gradle中加入
implementation 'com.devzld:expandlayout:1.0.0'
2、使用
你的实体类中加入一个是否展开的布尔型字段,例如:
data class TextBean(var text: String, var expand: Boolean)
在recyclerview的item布局中按需声明如下:
<com.zld.expandlayout.ExpandLayout
android:id="@+id/expand_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:collapseText="@string/foldHint"
app:contentTextColor="@color/text_color_normal"
app:contentTextSize="18sp"
app:ellipsizeText="..."
app:expandCollapseTextColor="#39a4d2"
app:expandCollapseTextGravity="right"
app:expandCollapseTextSize="16sp"
app:expandText="@string/expandHint"
app:maxCollapsedLines="3"
app:middlePadding="5dp"/>
在RecyclerView的onBindViewHolder方法中设置ExpandLayout的文字内容和展开状态,以及展开监听方法中将实体类的布尔型字段取反,同时调用notifyDataSetChanged()方法刷新列表
holder.expandLayout.setText(bean.text, bean.expand, object : ExpandLayout.OnExpandListener {
override fun expandChange() {
bean.expand = !bean.expand
notifyDataSetChanged()
}
})
配置好以上,就OK了
3、XML中配置的属性说明
xml中的属性 | 含义 ---|--- maxCollapsedLines | 收起时内容最多显示的行数,默认是3行 contentTextSize | 内容字体大小,默认18sp contentTextColor | 内容字体颜色 expandText | 扩展时显示的文字,默认是“全文” collapseText | 隐藏时显示的文字,默认是“收起” expandCollapseTextSize | 提示文字的大小,默认是18sp expandCollapseTextColor | 提示文字的颜色 expandCollapseTextGravity | 提示文字的位置,有left,right,center三种值,默认为left ellipsizeText | 超过最大行数时末尾显示的省略文字,默认是“...” middlePadding | 提示文字距离内容文字的高度,默认是0dp
Related Skills
node-connect
344.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
96.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
344.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
344.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
