TextView多文本折叠/展开效果

本文介绍了在Android开发中如何实现TextView的多文本折叠和展开效果,适用于内容过多时提高用户体验。通过布局文件调用、XML属性定义及Java代码设置,可以实现内容的显示、隐藏以及平滑动画效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景

在开发过程中,当我们的需求中包含说说或者评论等内容的展示时,我们都会考虑当内容太多时该如何显示。当内容的字数太多,如果全部展示出来可能会影响体验效果,但是又不能只截取一部分内容进行展示,此时就需要考虑使用多行显示折叠的效果来实现。

效果图:

多文本展示

使用

1.布局文件调用

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.wiggins.expandable.widget.MoreLineTextView
        android:id="@+id/tv_more_line_short"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:padding="@dimen/padding_small"
        app:clickAll="true"
        app:textColor="@color/red" />

    <View style="@style/spaceLine" />

    <com.wiggins.expandable.widget.expandable.ExpandableTextView
        android:id="@+id/tv_expandable_short"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:ellipsize="end"
        android:padding="@dimen/padding_small"
        android:textColor="@color/blue"
        app:allClickable="false"
        app:contentTextColor="@color/blue"
        app:isDisplayIcon="false"
        app:maxCollapsedLines="4" />

    <View style="@style/spaceLine" />

    <com.wiggins.expandable.widget.MoreLineTextView
        android:id="@+id/tv_more_line_long"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:padding="@dimen/padding_small"
        app:clickAll="true"
        app:textColor="@color/red" />

    <View style="@style/spaceLine" />

    <com.wiggins.expandable.widget.expandable.ExpandableTextView
        android:id="@+id/tv_expandable_long"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:ellipsize="end"
        android:padding="@dimen/padding_small"
        android:textColor="@color/blue"
        app:allClickable="false"
        app:contentTextColor="@color/blue"
        app:isDisplayIcon="false"
        a
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值