转载:http://www.2cto.com/kf/201409/330658.html

一、只想让TextView显示一行,但是文字超过TextView的长度怎么办?
在开头显示省略号

android:singleLine="true"
android:ellipsize="start"

在结尾显示省略号

android:singleLine="true"
android:ellipsize="end"

在中间显示省略号

android:singleLine="true"
android:ellipsize="middle"

横向自动滚动(跑马灯效果)

android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"

以上4个效果都要加上 android:singleLine="true",因为TextView默认是会自动换行的

android:ellipsize是设置文字过长时,该怎么显示

android:marqueeRepeatLimit="marquee_forever"是设置永远重复,当然你也可以设置具体的数字

android:focusable="true"和android:focusableInTouchMode="true"一定要加上,不然滚动效果出不来

二、怎么让TextView可以垂直滚动?
Java代码中加入下面一句话就可以实现垂直滚动:textView.setMovementMethod(ScrollingMovementMethod.getInstance());

三、怎么使TextView内容改变,跑马灯效果依然可以使用

重写TextView设置TextView一直处于选中状态:AlwaysMarqueeTextView.java

/*
* 重写TextView保证跑马灯效果一直显示
*/
public class AlwaysMarqueeTextView extends TextView { public AlwaysMarqueeTextView(Context context) {
super(context);
} public AlwaysMarqueeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
} public AlwaysMarqueeTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
} @Override
public boolean isFocused() {
return true;//一定要设置为true
}
}

最新文章

  1. Raneto Docs(开源的知识库建站程序)
  2. Caffe源码解析1:Blob
  3. 【原创】.NET Core应用类型(Portable apps & Self-contained apps)
  4. Android基础总结(1)
  5. 有关android源码编译的几个问题
  6. java.lang.IllegalStateException: attempt to re-open an already-closed object
  7. 初识Python装饰器
  8. flask中jinjia2模板引擎使用详解1
  9. windows7.0旗舰版安装后控制面板自带的Microsoft程序
  10. Dynamics CRM 导出系统中实体的属性字段到EXCEL
  11. [Swift]LeetCode128. 最长连续序列 | Longest Consecutive Sequence
  12. webpack4.0各个击破(7)—— plugin篇
  13. #018 C语言刷题 素数问题
  14. MySQL Innodb数据库误删ibdata1后MySQL数据库的恢复案例
  15. day 7-17 多表查询
  16. 史上最简单的 SpringCloud 教程 | 第一篇: 服务的注册与发现(Eureka)
  17. PMP:3.项目经理角色
  18. python魔法方法:__getattr__,__setattr__,__getattribute__
  19. kubernetes实战(二十五):kubeadm 安装 高可用 k8s v1.13.x
  20. 基于sklearn的 BaseEstimator开发接口:模型融合Stacking

热门文章

  1. [BZOJ4200][Noi2015]小园丁与老司机
  2. bootstrap之伪元素
  3. 使用mybatis-generator生成代码
  4. svn 应该忽略的文件(visual studio)
  5. 谈 CSS 模块化
  6. 安卓端360度全景图的html5实现
  7. 一鼓作气 博客--第七篇 note7
  8. xamarin 学习
  9. dom中一些节点获取和增改
  10. Css 相关资源(本篇不定期更新)