TextView跑马灯效果
2016-05-10 16:16
169 查看
首先,使用TextView实现走马灯形式的滚动显示,只需要对其设置两个属性:
但是,TextView的滚动显示,有一个前提,TextView需要必须处于focus状态。当TextView失去焦点的时候,TextView将会停止滚动。如何实现无限滚动,当然也需要从焦点入手。当然,直接requestFocus()是不行的,这里我使用了另外一个方法。观察到textView有一个名为isFocused()的方法,文档中的注释是这样的:
也就是说当TextView拥有焦点的时候会返回true.同时可以发现,TextView中很多地方都是直接调用这个方法作为判断条件,最关键的,这个方法被声明为public! ok, 实现方法已经初现端倪了!
做法是这样:比如,现在写一个类命名为一个AlwaysMarqueeTextView, 继承自TextView, 同时override isFocused()方法,并使其返回值为true, 样例如下:
[java]
view plain
copy
print?
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; } }
转自 :http://blog.csdn.net/hustpzb/article/details/5985063
相关:http://www.cnblogs.com/snowdrop/articles/1856469.html
android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever"
但是,TextView的滚动显示,有一个前提,TextView需要必须处于focus状态。当TextView失去焦点的时候,TextView将会停止滚动。如何实现无限滚动,当然也需要从焦点入手。当然,直接requestFocus()是不行的,这里我使用了另外一个方法。观察到textView有一个名为isFocused()的方法,文档中的注释是这样的:
/** * Returns true if this view has focus * * @return True if this view has focus, false otherwise. */
也就是说当TextView拥有焦点的时候会返回true.同时可以发现,TextView中很多地方都是直接调用这个方法作为判断条件,最关键的,这个方法被声明为public! ok, 实现方法已经初现端倪了!
做法是这样:比如,现在写一个类命名为一个AlwaysMarqueeTextView, 继承自TextView, 同时override isFocused()方法,并使其返回值为true, 样例如下:
[java]
view plain
copy
print?
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; } }
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; } }
转自 :http://blog.csdn.net/hustpzb/article/details/5985063
相关:http://www.cnblogs.com/snowdrop/articles/1856469.html
相关文章推荐
- android应用安装成功之后删除apk文件
- H5瀑布流如何实现
- HB制作的app版本更新
- MapGIS6.7_学习中遇到的问题(4):用户点文件(.txt)转MapGIS点文件(.WT)
- 指针和链条
- 2002
- BP神经网络识别手写数字项目解析及代码
- NGUI-Sprite扩展镜像功能
- 飞机程序第一节课
- UIWebView - 3
- ffmpeg filter过滤器 基础实例及全面解析
- 解决ViewPager的左右滑动和点击返回事件的冲突
- struts2 中dispatcher、redirect和chain三种result type的使用区别
- bestcoder 放盘子
- Cell的操作
- PO 与 VO
- Mentor.Graphics.AMS.v2011.1 Win32_64 1CD(电路设计)
- 一道传说中是百度面试的shell试题
- iOS开发的一些奇技
- Git详解之三 Git分支