<style name="scrolling line">
<item name="android:singleLine">true
<item name="android:ellipsize">marquee
<item name="android:marqueeRepeatLimit">marquee_forever
<item name="android:scrollHorizontally">true
<item name="android:focusable">true
<item name="android:focusableInTouchMode">true
</style>
可是這有個限制,就是要在focused的狀況下才會進行捲動。
那要怎麼讓他總是在捲動?很簡單,讓他永遠被focus就好了。
自訂一個類別繼承TextView,然後override以下方法:
@Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
if (focused) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
}
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
if (hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
}
}
@Override
public boolean isFocused() {
return true;
}
沒有留言:
張貼留言