自定義一個MyMarqueeTextView extends TextView,重寫他的三個構造方法,還有要重寫isFocused方法,並返回true
{
public AlwaysMarqueeTextView(Context context) {
super(context);
}
public AlwaysMarqueeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AlwaysMarqueeTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean isFocused() {
return true;
}
textView在佈局文件中設置如下屬性:
1.android:singleLine="true"
2.android:ellipsize="marquee"
3.android:focusableInTouchMode=“true”
4.android:focusable=“true”
基本上使用自定義的MyMarqueeTextView 以及在佈局文件中設置了上面四個屬性之後,就能在多個view的佈局文件中正常的滾動了,如果不能,嘗試加上下面的幾個屬性:
1.android:scrollHorizontally=“true”
2. android:marqueeRepeatLimit=“marquee_forever”
再如果TextView放置在layout中,而layout也設置了android:focusable =“true”,那麼此時可以在layout中加個屬性addStatesFromChildren=“true",即父控件子控件都能獲得焦點。