图
缩略
展开
布局
<TextView
android:id="@+id/txt_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:singleLine="true"
android:text="@{historyInfo.text}"
android:textColor="@android:color/black" />
<Button
android:id="@+id/btn_copy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/copy" />
重点在下面,意思是单行显示,超出部分文本在末尾显示...
android:ellipsize="end"
android:singleLine="true"
代码
holder.binding.txtContent.setOnClickListener(object : View.OnClickListener{
private var isShowAll = false
override fun onClick(p0: View?) {
isShowAll = !isShowAll
if (isShowAll) {
// 展开
holder.binding.txtContent.isSingleLine = false
holder.binding.txtContent.ellipsize = null
} else {
// 缩略
holder.binding.txtContent.isSingleLine = true
holder.binding.txtContent.ellipsize = TextUtils.TruncateAt.END
}
}
})