Android——跑马灯效果
来源:互联网 发布:自学java好还是培训好 编辑:程序博客网 时间:2024/05/22 10:38
跑马灯效果:
文字会慢慢走,这就是所谓的跑马灯效果。
需要在布局文件中添加几个属性:
<TextView android:id="@+id/tv" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="世界上最远的距离,不是爱,不是恨,而是熟悉的人,渐渐变得陌生。" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" />
但如果有多行文字,其实仅这些还不够实现,只有第一行会实现跑马灯,其他的不动,所以需要自定义view,将TextView稍加改
动。
新建一个类:
package com.example.paomadeng;import android.content.Context;import android.util.AttributeSet;import android.widget.TextView;public class MarqueeText extends TextView{ public MarqueeText(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } public MarqueeText(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } public MarqueeText(Context context) { super(context); // TODO Auto-generated constructor stub } @Override public boolean isFocused() { // TODO Auto-generated method stub return true; }}
isFocused设置为true,这样com.example.paomadeng.MarqueeText这个就可以替代TextView,
布局文件:
<com.example.paomadeng.MarqueeText android:id="@+id/tv" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="世界上最远的距离,不是爱,不是恨,而是熟悉的人,渐渐变得陌生。" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" />
这样就可以实现多行文字跑马灯 了。。。
1 0
- Android——跑马灯效果
- Android 跑马灯效果
- android跑马灯效果
- android跑马灯效果
- Android跑马灯效果
- Android 跑马灯效果
- android跑马灯效果
- android 跑马灯效果
- Android跑马灯效果
- android 跑马灯效果
- android 跑马灯效果
- Android跑马灯效果
- android 跑马灯效果
- Android 跑马灯效果
- Android跑马灯效果
- android 跑马灯效果
- Android跑马灯效果
- android跑马灯效果
- gitHub-How to Make a Computer Operating System
- 四档开启!windows7系统下载全新体验来袭!
- IFE糯米学院-正则表达式入门
- 解决生产环境上日志报事务回滚的问题
- 机房通信网设计
- Android——跑马灯效果
- OrangeUI-Delphi移动开发利器
- 4-2 多项式求值 (15分)
- myeclipse 快捷
- c++继承与多态概念的简单总结
- 定时任务实现Timer, TimeTask, ScheduledExecutorService及Spring定时器
- 下级不能比上级工资高吗?
- JAVA多线程
- mybatis中 insert into select 批量生成uuid时 用replace去掉"-"只生成一个uuid