TextView跑马灯效果
转载: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
}
}
TextView跑马灯效果的更多相关文章
- [Android1.5]TextView跑马灯效果
from: http://www.cnblogs.com/over140/archive/2010/08/20/1804770.html 前言 这个效果在两周前搜索过,网上倒是有转载,可恨的是转载之后 ...
- Android学习总结——TextView跑马灯效果
Android系统中TextView实现跑马灯效果,必须具备以下几个条件: 1.android:ellipsize="marquee" 2.TextView必须单行显示,即内容必须 ...
- 【Android】TextView跑马灯效果
老规矩,先上图看效果. 说明 TextView的跑马灯效果也就是指当你只想让TextView单行显示,可是文本内容却又超过一行时,自动从左往右慢慢滑动显示的效果就叫跑马灯效果. 其实,TextView ...
- Android TextView 跑马灯效果 - 2018年6月19日
第一步在布局中添加加粗部分代码: <TextView android:id="@+id/tv_company" android:layout_width="0dp& ...
- android 设置textview跑马灯效果
head_tv1.setEllipsize(TextUtils.TruncateAt.MARQUEE);head_tv1.setSingleLine(true);head_tv1.setSelecte ...
- TextView标签的属性和跑马灯效果
text:显示的内容 textSize:文本的大小 textColor:文本的颜色 visibility:可见性 默认可见,invisible:表示不可见,但对控件的显示区域做了保留 gone:隐藏 ...
- 设置TextView的密码效果以及跑马灯效果
密码效果以及跑马灯效果: xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...
- TextView 实现跑马灯效果
在String.xml中添加: <string name="txt">跑马灯效果,我跑啊跑</string>在layout/mian.xml中添加TextV ...
- Android界面(1) 使用TextView实现跑马灯效果
方法一:(只能实现单个TextView的跑马灯效果)在TextView添加以下控件 android:singleLine="true"只能单行,超出的文字显示为"...& ...
随机推荐
- 【总结】C# Access 数据库 增删查改 的简单步骤
引用集: using System.Data.OleDb; static string exePath = System.Environment.CurrentDirectory;//本程序所 ...
- postman测试接口之POST提交本地文件数据
前言: 接口测试时,有时需要读取文件的数据:那么postman怎么添加一个文件作为参数呢? 实例: 接口地址: http://121.xxx.xxx.xxx:9003/marketAccount/ba ...
- CentOS 简单设置samba服务
1.安装 yum -y install samba 2.设置配置文件 1) 备份Samba的配置文件:cp /etc/samba/smb.conf /etc/samba/smb.conf.bak ...
- python实现最简单的计算器功能源码
import re def calc(formula): formula = re.sub(' ', '', formula) formula_ret = 0 match_brackets = re. ...
- About_Smarty
Smarty是一个使用PHP写出来的模板PHP模板引擎,是目前业界最著名的PHP模板引擎之一.它分离了逻辑代码和外在的内容,提供了一种易于管理和使用的方法,用来将原本与HTML代码混杂在一起PHP代码 ...
- 响应式web网站设计制作方法
在研究响应式的时候,记录了一些感想,分享出来,抛砖引玉,希望可以和大家一起讨论.总结下来,响应式比之前想象的要复杂得多.1. ie9以下(不包括ie9)采用ie条件注释,为ie8以及一下单独开一个样式 ...
- VS2010 ERROR:c1xx fatal error c1083
在VS2010中新建文件夹,然后在文件夹内新建文件polling.cpp,可是在项目中不现实该cpp文件,所以就在在硬盘上将该文件删除,编译报错. >c1xx : fatal error C10 ...
- 续关于C#的微信开发的入门记录一
前几天写了一篇博客<关于C#的微信开发的入门记录一>,原文地址:http://www.cnblogs.com/zhankui/p/4515905.html,现在继续完善: 目前很多小伙伴都 ...
- myBatis中 collection 或 association 联合查询 中column 传入多个参数值
下面是一个树形结构表自连接 联合查询 Demo <resultMap id="BaseResultMap" type="com.maidan.daas.entit ...
- win7安装oracle 时容易出的问题
Windows7下安装Oracle11G.10G,都会提示如下信息 正在检查操作系统要求... 要求的结果: 5.0,5.1,5.2,6.0 之一 实际结果: 6.1 检查完成.此次检查的总体结果为: ...