实现的原理为设置TextView的属性,lines,默认可以设置为一行或者两行,当点击的时候,将lines属性设置为多行,就可以实现我们想要的效果。
<TextView
android:id="@+id/tv_trademark_explanation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:drawableBottom="@drawable/tv_down_arrow"
android:drawablePadding="10dp"
android:ellipsize="end"
android:lines="2"
android:paddingBottom="11dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text=""
android:textColor="@color/text_color_646464"
android:textSize="13sp" />
switch (tag) {
case 2:
tv_trademark_explanation.setMaxLines(100);
tag = 1;
break;
case 1:
tv_trademark_explanation.setLines(2);
tag = 2;
break;
default:
break;
}
break;