背景
在开发过程中,当我们的需求中包含说说或者评论等内容的展示时,我们都会考虑当内容太多时该如何显示。当内容的字数太多,如果全部展示出来可能会影响体验效果,但是又不能只截取一部分内容进行展示,此时就需要考虑使用多行显示折叠的效果来实现。
效果图:
使用
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"
app:maxCollapsedLines="4" />
</LinearLayout>
2.Java文件调用
private void initData() {
mTvMoreLineShort.setText(Constant

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

被折叠的 条评论
为什么被折叠?



