作者:手机用户2502937497 | 来源:互联网 | 2023-05-16 18:59
基本使用:studio中直接引用compilecom.ms-square:expandableTextView:0.1.4,然后可以在代码中使用,用法和TextView一样。布局文件:<
基本使用:studio中直接引用 compile 'com.ms-square:expandableTextView:0.1.4',然后可以在代码中使用,用法和TextView一样。
布局文件:
xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_match_parent"
android:layout_match_parent"
android:orientation="vertical">
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:expandableTextView="http://schemas.android.com/apk/res-auto"
android:id="@+id/expand_text_view"
android:layout_match_parent"
android:layout_wrap_content"
android:clickable="false"
android:orientation="vertical"
expandableTextView:clickListenerType="all"
expandableTextView:collapseDrawable="@drawable/ic_collapse_large_holo_light"
expandableTextView:expandDrawable="@drawable/ic_expand_large_holo_light"
expandableTextView:maxCollapsedLines="2">
android:id="@id/expandable_text"
android:layout_match_parent"
android:layout_wrap_content"
android:clickable="false"
android:textColor="#000" />
android:id="@+id/expand_footer"
android:layout_match_parent"
android:layout_wrap_content">
android:id="@id/expand_collapse"
android:layout_20dp"
android:layout_20dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="@android:color/transparent"
android:clickable="false" />
ExpandableTextView是
一个容器,包含了文字显示部分TextView 以及触发展开收起的按钮(那个小箭头)ImageButton,触发按钮可以根据需求自定义,替换成自己的。
ExpandableTextView的一些属性:
maxCollapsedLines 当TextView 收起的时候允许显示的最大行数。
expandDrawable 展开按钮的图片
collapseDrawable 收起按钮的图片
使用中需要注意的问题:
如果是在listview中作为一个条目使用,那么在复用的时候,会出现问题,就是复用那些展开的条目,都是展开的。
解决办法如下:
在adapter中添加这行代码 private SparseBooleanArray mConvertTextCollapsedStatus = new SparseBooleanArray();
设置文本的时候,不要直接用setText(list.get(position)), 用viewHolder.mExpandableTextView.setText(list.get(position), mConvertTextCollapsedStatus, position);