小技巧:TextView 展开收起
来源:互联网 发布:php 编译mysql 编辑:程序博客网 时间:2024/06/04 20:05
直接上代码:
布局: <TextView android:id="@+id/tv_info" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/spacing_15dp" android:layout_marginRight="@dimen/spacing_15dp" android:layout_marginTop="@dimen/spacing_6dp" android:ellipsize="end" android:textColor="@color/btn_small_text" android:textSize="12sp" /> <TextView android:id="@+id/tv_more" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginRight="@dimen/spacing_8dp" android:gravity="right" android:padding="@dimen/spacing_7dp" android:text="展开" android:textColor="@color/main_green_color" android:textSize="12sp" android:visibility="gone" />
private void intView(){ tvMore.setText("展开"); tvInfo.setMaxLines(100000);//设置足够大行数;让文字全部展开 tvInfo.setText("要设置的文字"); int lineCount = tvInfo.getLineCount(); if (lineCount > 4/*最多显示行数,超过这个行数则显示展开按钮*/) { tvInfo.setMaxLines(4); tvMore.setVisibility(View.VISIBLE); } else { tvMore.setVisibility(View.GONE); }} @Override public void onClick(View v) { if (v == tvMore) { if (tvMore.getText().equals("展开")) { tvInfo.setMaxLines(100000); tvMore.setText("收起"); } else { tvInfo.setMaxLines(4); tvMore.setText("展开"); } } }
哈哈, 就这么简单就实现 折叠功能了。
1 0
- 小技巧:TextView 展开收起
- TextView展开和收起
- TextView单击展开收起功能
- Textview文字的收起与展开功能
- 自定义view实现TextView展开收起效果
- 一种可以展开收起的TextView
- TextView 显示收起 展开的bug
- Reclyclerview 的条目的textview展开,收起
- Textview自带展开和收起功能
- 自定义可展开收起TextView,展开收起按钮紧跟文本内容
- android TextView 文本内容收起,展开的效果实现
- 两点技巧-给TextView添加Tag,点击空白收起键盘
- TextView 小技巧
- android textview小技巧
- 宏展开的小技巧
- jquery 菜单展开收起
- 展开收起特效
- 展开与收起效果
- 方格分割(DFS搜索算法)
- 一次python爬虫爬取p站的经历
- ko绑定----记录
- centos6.5安装oracle11g
- BZOJ 1269: [AHOI2006]文本编辑器editor 分离合并Splay
- 小技巧:TextView 展开收起
- VMware中Centos7的静态ip设置
- git 报错 RPC failed; curl 18 transfer closed with outstanding read data remaining
- 剑指offer复习笔记1
- Ubuntu下.py文件的运行
- Linux学习笔记17
- poj 3465 贪心+优先队列 叉姐的魔法训练
- 程序员的情书(发现就更新)
- type定义函数类型