用代码简单的实现跑马灯效果
2016-01-06 20:26
495 查看
在res资源文件夹下的layout中定义一个TextView控件代码如下:
其中string中是你实现效果的文字。这样就可以实现你的跑马灯效果了。
如果想要同时实现两个跑马灯效果,需要你重新定义一个类来继承TextView然后重写它的三个方法,最后需要在重载他的一个isFocused方法,让它return
true;
.最后一步就是,用我们自定义的这个类(com.imooc.包名.类名)来替代textview.如下:
<TextView android:text="@string/hehe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" />
其中string中是你实现效果的文字。这样就可以实现你的跑马灯效果了。
如果想要同时实现两个跑马灯效果,需要你重新定义一个类来继承TextView然后重写它的三个方法,最后需要在重载他的一个isFocused方法,让它return
true;
.最后一步就是,用我们自定义的这个类(com.imooc.包名.类名)来替代textview.如下:
<com.example.android_06_demo.MyclassTextView android:text="@string/hehe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" /> <com.example.android_06_demo.MyclassTextView android:text="@string/hehe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" />这样就可以同时实现两个跑马灯的效果了。
相关文章推荐
- eclipse学习心得
- [编程题] 明明的随机数
- 时间工具 java
- C++命名空间
- springMvc 拦截器
- Python项目小结
- [编程题] 汽水瓶
- 在Windows Server 2008 R2上安装Ftp服务
- java jar war 打包
- java+selenium Q&A
- Java中的抽象类与接口
- INSERTDELETES&NOINSERTDELETES--GoldenGate Parameter
- Python数据类型
- spring注解
- Elasticsearch源码加载到eclipse调试
- php判断IE浏览器
- Qt获取本地网络信息的实例
- Python学习手册 - 04
- c语言学习之语句篇
- Spring-web源码解析之Initializer