如何使用ExpandableTextView

展现文字折叠效果  如图

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



使用方法:

新建一个工程

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 里面设置文本内容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值