Android TextView展开显示全部

Android TextView展开显示全部

缩略
在这里插入图片描述
展开
在这里插入图片描述

布局

            <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
                }
            }
        })

完事

发布了103 篇原创文章 · 获赞 31 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/sinat_38184748/article/details/103487558