android不获取焦点也可以实现跑马灯效果

public class MarqueeTextView extends TextView{
 private boolean mMarquee = false;

 public MarqueeTextView(Context context, AttributeSet attrs) {
  super(context, attrs);
 }

 public void setMarquee(boolean marquee) {
  mMarquee = marquee;
 }

 @Override
 public 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 mMarquee;
 }

}

你可能感兴趣的:(android开发)