android----TextView如何实现无限滚动显示
2010-11-05 21:06
846 查看
首先,使用TextView实现走马灯形式的滚动显示,只需要对其设置两个属性:
但是,TextView的滚动显示,有一个前提,TextView需要必须处于focus状态。 当TextView失去焦点的时候,TextView将会停止滚动。如何实现无限滚动,当然也需要从焦点入手。当然,直接requestFocus()是不行的,这里我使用了另外一个方法。观察到textView有一个名为isFocused()的方法,文档中的注释是这样的:
也就是说当TextView拥有焦点的时候会返回true.同时可以发现,TextView中很多地方都是直接调用这个方法作为判断条件,最关键的,这个方法被声明为public! ok, 实现方法已经初现端倪了!
做法是这样:自定义一个OOXXTextView, 继承自TextView, 同时override isFocused()方法,并使其返回值为true, 样例如下:
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, 实现方法已经初现端倪了!
做法是这样:自定义一个OOXXTextView, 继承自TextView, 同时override isFocused()方法,并使其返回值为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; } }
相关文章推荐
- Android----Android之TextView实现文字过长时省略部分或者滚动显示 (跑马灯)
- 【转】Android之TextView实现文字过长时省略部分或者滚动显示
- Android开发中TextView文本过长滚动显示实现方法分析
- Android 如何实现带滚动条的TextView,在更新文字时自动滚动到最后一行?
- Android 如何实现带滚动条的TextView,在更新文字时自动滚动到最后一行
- Android之TextView实现文字过长时省略部分或者滚动显示
- Android实现在TextView文字过长时省略部分或滚动显示的方法
- Android之TextView实现文字过长时省略部分或者滚动显示
- android通知公告栏,textview滚动显示上网实现
- Android之TextView实现文字过长时省略部分或者滚动显示
- Android TextView实现水平滚动显示效果
- Android之TextView实现文字过长时省略部分或者滚动显示
- Android之TextView实现文字过长时省略部分或者滚动显示
- Android之TextView实现文字过长时省略部分或者滚动显示
- android TextView实现滚动显示效果
- Android 如何实现带滚动条的TextView,在更新文字时自动滚动到最后一行?
- Android之TextView实现文字过长时省略部分或者滚动显示
- Android之TextView实现文字过长时省略部分或者滚动显示
- Android 如何实现带滚动条的TextView,在更新文字时自动滚动到最后一行
- Android之TextView实现文字过长时省略部分或者滚动显示