首页 > 其他 > 详细

ExpandableTextView正确使用

时间:2017-03-11 22:17:13      阅读:1425      评论:0      收藏:0      [点我收藏+]

下载ExpandableTextView库,新建项目关联库。使用关键点:要把ExpandableTextView放在LinearLayout布局下,否则点击展开,收起按钮,文本不能展开,收起。

在activity代码

ExpandableTextView expandTextView= (ExpandableTextView) findViewById(R.id.expand_text_view);

expandTextView.setText("注意:ExpandableTextView要放在线性布局里,这样文本才能上下缩放!maxCollapsedLines设置行数,如果超过按钮显示,文本收起;contentTextSize文本大小;contentTextColor文本颜色;expandDrawable展开按钮图片;expandText展开按钮文本;collapseDrawable折叠按钮图片;collapseText折叠按钮文本;DrawableAndTextGravity按钮位置 ,center,left,right可选");


xml布局:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    >

<!-- 注意:ExpandableTextView要放在线性布局里,这样文本才能上下缩放! -->


<!-- maxCollapsedLines设置行数,如果超过按钮显示,文本收起 -->

<!-- contentTextSize文本大小 -->

<!-- contentTextColor文本颜色 -->

<!-- expandDrawable展开按钮图片 -->

<!-- expandText展开按钮文本 -->

<!-- collapseDrawable折叠按钮图片 -->

<!-- collapseText折叠按钮文本 -->

<!-- DrawableAndTextGravity按钮位置 ,center,left,right可选 -->



    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="vertical" >

        <me.chensir.expandabletextview.ExpandableTextView

            android:id="@+id/expand_text_view"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            app:maxCollapsedLines="2" 

            app:contentTextSize="20sp"

            app:contentTextColor="#ff0000"

            app:expandText="显示"

            app:collapseText="隐藏"

            app:DrawableAndTextGravity="center">

        </me.chensir.expandabletextview.ExpandableTextView>

    </LinearLayout>


</RelativeLayout>


本文出自 “12680972” 博客,请务必保留此出处http://12690972.blog.51cto.com/12680972/1905393

ExpandableTextView正确使用

原文:http://12690972.blog.51cto.com/12680972/1905393

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!