文字的跑马灯效果
来源:互联网 发布:实体店买到网络专供款 编辑:程序博客网 时间:2024/04/30 13:35
如何实现TextView的Marquee效果
往往看到一些应用的标题栏中当标题超出时便会自动滚动
这篇文章要讲的就是如何去实现TextView的Marquee效果
其实TextView已经自带了如何实现滚动的属性
- android:singleLine="true"
- android:ellipsize="marquee"
- android:marqueeRepeatLimit="marquee_forever"
通过上面的属性设置就能让TextView滚动起来。当然也可以通过代码去设置。
但是当设置完之后发现并没有滚动起来,原来TextView滚动的前提是这个空间必须要获得焦点。TextView需要必须处于focus状态。
在TextView的父类View中有一个方法isFocused(),系统通过这个方法去判断一个空间是否获得焦点。
所以我们就有了解决方案:
写一个子类继承TextView,重写isFocused()方法,直接返回true。当通过这个函数去判断TextView有没有获得焦点时,总是返回获得焦点于是我们的TextView就开始滚动起来了。代码很简单:
- public class AlwaysMarqueeTextView extends TextView {
- /**
- * constructor
- * @param context Context
- */
- public AlwaysMarqueeTextView(Context context) {
- super(context);
- }
- /**
- * constructor
- * @param context Context
- * @param attrs AttributeSet
- */
- public AlwaysMarqueeTextView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- /**
- * constructor
- * @param context Context
- * @param attrs AttributeSet
- * @param defStyle int
- */
- public AlwaysMarqueeTextView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
- @Override
- public boolean isFocused() {
- return true;
- }
- }
0 0
- 文字的跑马灯效果
- 文字跑马灯效果
- 文字 跑马灯 效果
- 文字跑马灯效果
- 文字跑马灯效果
- 文字跑马灯效果
- 文字跑马灯效果
- android 文字的跑马灯效果
- android 文字的跑马灯效果
- 实现文字的跑马灯效果,Textview
- Android 文字跑马灯效果
- Android 文字跑马灯效果
- android 文字跑马灯效果
- 文字跑马灯效果代码
- TextView文字跑马灯效果
- TextView跑马灯效果,也就是,自动滚动文字的效果。
- 跑马灯效果 文字上下滚动效果
- Textview的文字滚动,跑马灯效果的实现
- 将View存成bitmap,去色,作为button背景
- android sdk manager 无法更新问题解决
- iis出现 Server Application Error 错误解决方法
- 状态模式和策略模式
- 好吧,我也开始写学习博客了
- 文字的跑马灯效果
- 括号匹配+catlan数
- CAGradientLayer使用
- ffmpeg来进行视频编码
- Ubuntu rhythombox 乱码解决
- dom4j学习总结(一)
- 对于 原文:(迁移Mysql数据库到Azure上的SQL database) 的补充(windows azure国内运营商)
- UVa 101 The Blocks Problem
- 转载一篇好文章js实现动态添加和删除多个附件。