当我们有的时候需要TextView展示一部分的内容,然后点击某按钮,会将另外的部分展现出来。效果图如下:
下面上代码,其实非常的简单
1.导入依赖:compile ‘com.ms-square:expandableTextView:0.1.4’
2.在你的XML文件中复制下面的代码(如果你不是对命名有要求,不需要更改,直接复制就可以)
<com.ms.square.android.expandabletextview.ExpandableTextView
android:layout_width="match_parent"
android:id="@+id/expand_text_view"
android:layout_height="wrap_content"
expandableTextView:maxCollapsedLines="4"
expandableTextView:animDuration="200">
<TextView
android:id="@id/expandable_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textSize="16sp"
android:textColor="#666666" />
<ImageButton
android:id="@id/expand_collapse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:layout_gravity="right|bottom"
android:background="@android:color/transparent"/>
</com.ms.square.android.expandabletextview.ExpandableTextView>
expand = (ExpandableTextView) findViewById(R.id.expand_text_view);
expand.setText("dsakgjfndjkgnjkfndj" +
"kgnfjdnjgnfjkdngjkfndjkgnffffffffffffffffffff" +
"fffffffffffkjfakjngjbcvnxznm,bjktjksnbjkfnjkbnjfnklg nflknlgk" +
"nfjkdnskjnoeujbgfjknssjknfjnbm,n ktsrnsrbknvcm,nxzkjnjkrfangiob" +
"nrtofesabnjtgnbjnjkfdnjlbnjklvfndsljkbnjkfnsjknbf/nfdukshgohroewio" +
"gviolcdfxiosavrevfedagf/nwefewfdsafdsahbgjhkcbxaikbrujikwbnavujnhb" +
"fujieabnhvujikbhujikfbujikbvfujkbjkavkjfbvkafvbkfvdbjkfkjfjkakjkb" +
"jkbjkbjkbjbjkbjkbjkvcjkxzbjk brkebvkbf");
4.完事了,根本不用管按钮什么的