跑马灯
自定义View
package com.example.dao;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class MaequeeText extends TextView {
public MaequeeText(Context context) {
super(context);
}
// 重写所有的构造函数 Source==>Generate Constructors from Superclass
public MaequeeText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MaequeeText(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean isFocused() {
return true;
// 自定义设置让focusable为true
// 这个方法相当于在layout中
// android:focusable="true"
// android:focusableInTouchMode="true"
}
}
XML
<com.example.dao.MaequeeText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:text="你必须非常努力,才能看起来毫不费劲,你必须非常努力,才能看起来毫不费劲." />