可展开(Expand)的TextView,保留了TextView的属性,方便易用(TextView that can expand/collapse in some way easier. )
参考开源项目ExpendableTextView,
原项目使用LinearLayout包装TextView和Button的做法,需要保证id的一致,文本内容需要在代码中设置,操作较为复杂,笔者的做法则更加简单简洁一些,
直接继承自TextView,保留TextView完整特性,且简化了操作,核心思想就是动态的设定TextView的padding值。
本控件解决了不同分辨率下适配的问题,增加了一些新的属性,优化了像setMaxLine()/setMaxHeight()会导致的多次requestLayout的问题,解决了在列表控件中使用会出现的展开/折叠错位的问题。
同样也良好的支持了列表控件,RecyclerView,ScrollView,AbsListView等。
compile 'com.lcodecorex:extextview:1.0.2'
<com.lcodecore.extextview.ExpandTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="@string/test"
android:textColor="#666666"
android:textSize="16sp"
app:arrowAlign="center"
app:arrowPadding="8dp"
app:arrowPosition="below"
app:maxCollapsedLines="4" ></com.lcodecore.extextview.ExpandTextView>
其它按TextView的使用方法使用即可。
et.setOnExpandStateChangeListener() 可以监听展开和折叠状态的变化。
void onChangeStateStart(boolean willExpanded);
void onExpandStateChanged(TextView textView, boolean isExpanded);