MarqueeTextView類代碼:
public class MarqueeTextView extends TextView{
public MarqueeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
// TODO Auto-generated method stub
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
// TODO Auto-generated method stub
if(hasWindowFocus) super.onWindowFocusChanged(hasWindowFocus);
}
@Override
@ExportedProperty(category = "focus")
public boolean isFocused() {
return true;
}
}
XML佈局文件相關代碼:
<com.barry.components.MarqueeTextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:freezesText="true"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:scrollHorizontally="true"
android:singleLine="true" />
<!--width設爲具體大小也行。--!>