一个页面多个TextView跑马灯,与焦点无关
package com.travelsky.bluesky.utils; import android.content.Context; import android.graphics.Rect; import android.text.TextUtils; import android.util.AttributeSet; import android.widget.TextView; /** * 跑马灯效果 textview * @author zbtu * @date 2013-4-22 上午8:55:44 */ public class MarqueeTextView extends TextView { public MarqueeTextView(Context context) { this(context, null); } public MarqueeTextView(Context context, AttributeSet attrs) { super(context, attrs); setFocusable(true); setFocusableInTouchMode(true); setSingleLine(); setEllipsize(TextUtils.TruncateAt.MARQUEE); setMarqueeRepeatLimit(-1); } public MarqueeTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFocusable(true); setFocusableInTouchMode(true); setSingleLine(); setEllipsize(TextUtils.TruncateAt.MARQUEE); setMarqueeRepeatLimit(-1); } @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { if (focused) { super.onFocusChanged(focused, direction, previouslyFocusedRect); } } @Override public void onWindowFocusChanged(boolean focused) { if (focused) { super.onWindowFocusChanged(focused); } } @Override public boolean isFocused() { return true; } }
因为已经做了焦点等处理,所以不用再配置
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_vertical"
android:marqueeRepeatLimit="marquee_forever"
直接引用即可
---------------------------------------------------------------------------------------------------------------------------------
copyright:http://www.cnblogs.com/anee/