跑马灯
来源:互联网 发布:文学阅读软件 编辑:程序博客网 时间:2024/04/30 06:43
Android系统中TextView实现跑马灯效果,必须具备以下几个条件:
1、android:ellipsize=”marquee”
2、TextView必须单行显示,即内容必须超出TextView大小
3、TextView要获得焦点才能滚动
XML代码:
android:ellipsize="marquee", android:singleLine="true"
Java代码:
mTVText.setText("哼唱接撒砥砺风节雷锋精神http://orgcent.com/,很长很长很长很长很长很长的数据");
mTVText.setSingleLine(true);
mTVText.setEllipsize(TruncateAt.MARQUEE);
PS: TextView.setHorizontallyScrolling(true); //让文字可以水平滑动
TextView还可以设置跑马灯效果的滚动次数,如下:
XML代码设置:
android:marqueerepeatlimit="1"。1代表1次,-1代表无限循环。
Java代码设置:
mTVText.setMarqueeRepeatLimit(-1);
1、android:ellipsize=”marquee”
2、TextView必须单行显示,即内容必须超出TextView大小
3、TextView要获得焦点才能滚动
XML代码:
android:ellipsize="marquee", android:singleLine="true"
Java代码:
mTVText.setText("哼唱接撒砥砺风节雷锋精神http://orgcent.com/,很长很长很长很长很长很长的数据");
mTVText.setSingleLine(true);
mTVText.setEllipsize(TruncateAt.MARQUEE);
PS: TextView.setHorizontallyScrolling(true); //让文字可以水平滑动
TextView还可以设置跑马灯效果的滚动次数,如下:
XML代码设置:
android:marqueerepeatlimit="1"。1代表1次,-1代表无限循环。
Java代码设置:
mTVText.setMarqueeRepeatLimit(-1);
当有些情况下需要是文字一直滚动以引起用户注意,这是可以使用派生TextView,
重载onFocusChanged,onWindowFocusChanged,isFocused 这三个方法。
修改一下本例,添加一个ScrollAlwaysTextView类:
重载onFocusChanged,onWindowFocusChanged,isFocused 这三个方法。
修改一下本例,添加一个ScrollAlwaysTextView类:
public class ScrollAlwaysTextView extends TextView { public ScrollAlwaysTextView(Context context) { this(context, null); } public ScrollAlwaysTextView(Context context, AttributeSet attrs) { this(context, attrs, android.R.attr.textViewStyle); } public ScrollAlwaysTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { if (focused) super.onFocusChanged(focused, direction, previouslyFocusedRect); } @Override public void onWindowFocusChanged(boolean focused) { if (focused) super.onWindowFocusChanged(focused); } @Override public boolean isFocused() { return true; }}
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- 跑马灯
- Sql Server中的日期与时间函数
- android代码混淆方法
- java 关于xml的注解,自动生成xml文件 - @XML***
- 防火墙问题
- 为什么我们同时搞acm,结果是你就可以去final
- 跑马灯
- 固定宽高的DIV绝对居中示例
- UVA 10534 Wavio Sequence
- 算法导论 4.3-1
- windows下mysql忘记root密码的解决办法 201
- OpenID简介
- findbugs 出现的问题解析
- HDU 4620 Fruit Ninja Extreme
- 线上MySQL 32G大小的表truncate所消耗的时间为2分钟,快还是慢?