您的位置:首页 > 其它

如何使用ExpandableTextView

2016-10-22 17:27 218 查看
展现文字折叠效果  如图





原本以为要自己自定义,后来才知道已经第三方控件,直接拿来用就好了

使用方法:

新建一个工程

dependencies 添加
compile 'com.ms-square:expandableTextView:0.1.4'
XML 布局文件
<com.ms.square.android.expandabletextview.ExpandableTextView
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_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
expandableTextView:maxCollapsedLines="5"
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:text="aasdasdasdasdasdas"
android:textColor="#666666" />
<ImageButton
android:id="@id/expand_collapse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_gravity="right|bottom"
android:background="@android:color/transparent"/>
</com.ms.square.android.expandabletextview.ExpandableTextView>

然后fbc
private void initView() {
ExpandableTextView expand_text_view= (ExpandableTextView) findViewById(R.id.expand_text_view);
expand_text_view.setText("\n" +
"予观夫巴陵胜状,在洞庭一湖。衔远山,吞长江,浩浩汤汤,横无际涯;朝晖夕阴,气象万千。此则岳阳楼之大观也,前人之述备矣。然则北通巫峡,南极潇湘,迁客骚人,多会于此,览物之情,得无异乎?\n" +
"若夫淫雨霏霏,连月不开,阴风怒号,浊浪排空;日星隐曜,山岳潜形;商旅不行,樯倾楫摧;薄暮冥冥,虎啸猿啼。登斯楼也,则有去国怀乡,忧谗畏讥,满目萧然,感极而悲者矣。\n");
}

然后就可以了

注意要在ExpandableTextView 里面设置文本内容
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: