要实现跑马灯效果。指定的TextView必须获得焦点。而一个界面只有一个view占据焦点。所以必须重写要实现的Textview。如下:
import android.content.Context;import android.graphics.Rect;import android.util.AttributeSet;import android.widget.TextView;public class ForcedTextView extends TextView { public ForcedTextView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { if(focused) { super.onFocusChanged(focused, direction, previouslyFocusedRect); } } public void onWindowFocusChanged(boolean hasWindowFocus) { if(hasWindowFocus) { super.onWindowFocusChanged(hasWindowFocus); } } public boolean isFocused() { return true; } }
?让Textview一直把持住焦点。就可以实现要的效果啦!!!