跑马灯实现要素:
1、android:singleLine="true";TextView的内容显示为一行。内容不满一行不滚动显示。内容超过控件长度,跑马灯显示。此处的属性只能选择singleLine,不能使用maxLines。
2、android:ellipsize="marquee"
3、android:focusable="true"
4、android:marqueeRepeatLimit="marquee_forever"
5、java代码中可以设置musicName.setSelected(true);
6、需要TextView一直保持焦点。所以需要自定义一个TextView继承TextView,覆写isFocused方法,返回true,使焦点一直存在。
public class MarqueeTextView extends TextView {
public MarqueeTextView(Context context) {
super(context);
}
public MarqueeTextView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public MarqueeTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override