Android 跑马灯


跑马灯的效果,我看到好多文章就想笑。很多文章都有一句,文字不能比TextView长。我了个去,有点脑子的都知道,文字没有TextView长的话还需要跑马吗?全显示出来了还需要跑马?

跑马灯的效果默认是需要获得焦点才有效。为了任何时候有效,可以继承Textiew,重写IsFocused方法,返回true。

本文工程源码下载:

免费下载地址在 http://linux.bkjia.com/

用户名与密码都是www.bkjia.com

具体下载目录在 /pub/Android源码集锦/2011年/12月/Android 跑马灯/

  1. public class MarqueeTextView extends TextView {  
  2.   
  3.     public MarqueeTextView(Context context) {  
  4.         super(context);  
  5.     }  
  6.     public MarqueeTextView(Context context, AttributeSet attrs){  
  7.         super(context,attrs);  
  8.     }  
  9.     public MarqueeTextView(Context context, AttributeSet attrs, int defStyle){  
  10.         super(context, attrs, defStyle);  
  11.     }  
  12.     public boolean isFocused(){  
  13.         return true;  
  14.     }  
  15.   
  16. }  
然后TextView配置属性
  1. mText.setSingleLine(true);  
  2. mText.setEllipsize(TruncateAt.MARQUEE);  
 
  1. mText.setMarqueeRepeatLimit(-1);  
Ok了

相关内容