1.跑马灯用到的TextView相关属性
XML中的属性 | 跑马灯用到的设置方法 | 说明 |
singleLine | setSingleLine | 指定文本是否单行显示 |
ellipsize | setEllipsize | 指定文本超出范围后的省略方式 |
focusable | setFocusable | 指定是否获得焦点,跑马灯效果要求设置为true |
focusableInTouchMode | setFocusableInTouchMode | 指定在触摸时是否获得焦点,跑马灯效果要求设置为true |
2.ellipsize属性取值说明
XML中的省略方式 | TruncateAt类中省略方式 | 说明 |
start | START | 省略号在开头 |
middle | MIDDLE | 省略号在中间 |
end | END | 省略号在末尾 |
marquee | MARQUEE | 跑马灯显示 |
这里也包含了末尾省略的方式
3.跑马灯举例
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="快讯:红色预警,超强台风“莫兰蒂”即将登陆,请居民关紧门窗、备足粮草,做好防汛救灾准备!"/>