您的位置:首页 > 移动开发 > Android开发

android TextView实现跑马灯效果

2015-02-03 09:22 585 查看
首先新建一个项目

在Layout布局中 吧TextView的属性设置为:

android:singleLine="true"

android:ellipsize="marquee"

android:focusable="true"

android:focusableInTouchMode="true"

但是在复杂的布局中,只能第一个实现,如果有第二个TextView则实现不了跑马灯的效果

所以我们需要进一步修改一下:

在src新建一个类,我们可以命名为marqueeTextView

1、让继承TextView

2、导入TextView的三个方法 这里有一个小技巧:鼠标右键 选择Source 然后点击Generate Constructors from Superclass 然后点击OK即把所以的方法都加进去了。

3、然后再加入 public boolean isFocused() {

// TODO Auto-generated method stub

return true;

}

的方法。

4、在返回Layout布局中 把<TextView />改为<com.example.marqueetextview.MarqueeTextView />

5、这样所有的TextView都可实现跑马灯的效果。

大家可以查看我的小网站:我的网站 www.sfyblog.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: