跑马灯:实现长文本的滚动展示
一个跑马灯(省略一些属性)
<TextView
android:singleLine = "true"
android:ellipsize = "marquee"
android:focusable = "true"
android:focusableInTouchMode = "true" />
但是我们发现,复制两份代码不能实现两个跑马灯效果
解决方法:自定义类继承TextView
class MyMarquee extends TextView {
/**三个构造函数**/
@override
public boolean isFocused() {
/**自定义强制获取焦点**/
return true;
}
}
然后 —包名+类名
<com.example.main.MyMarquee
android:singleLine = "true"
android:ellipsize = "marquee"
android:focusable = "true"
android:focusableInTouchMode = "true" />
就可以实现两个跑马灯效果