ExpandableTextView——一个可折叠的Textview,移动商城app开发

重要的是:

1、TextView 和ImageButton 的id必须按照库要求的设置,分别设置为”@id/expandable_text” 和”@id/expand_collapse” ,只有这样才能生效。

2、当然,你也可以设置以下属性满足你项目的需要。

maxCollapsedLines 折叠的时候允许显示的最大行,默认为8

animDuration 折叠展开时动画所用的时间,默认300ms

animAlphaStart 动画执行的时候,渐变动画,背景虚化。默认为0.7f,设置为1,则不会有虚化。

expandDrawable 你自定义展开动画。

collapseDrawable 你自定义折叠动画。

三、小例子。

<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”

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>

// sample code snippet to set the text content on the ExpandableTextView

ExpandableTextView expTv1 = (ExpandableTextView) rootView.findViewById(R.id.sample1)

.findViewById(R.id.expand_text_view);

// IMPORTANT - call setText on the ExpandableTextView to set the text content to display

expTv1.setText(getString(R.string.dummy_text1));

需要注意的是,设置文本内容时候我们用的是ExpandableTextView 而不是Textview。

看效果

展开前:

这里写图片描述

展开后

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值