csschn

Android,你等等我。。。

导航

使用TextView实现跑马灯效果

  我们在页面上添加了一个TextView控件之后,如果要显示的内容很少,可以一目了然。但是如果要显示的内容比较多,就会出现显示不全等问题,

  1. 如果只是单行的TextView,我们可以设置以下四个属性就可以实现跑马灯效果;
    • android:singleLine="true"
    • android:ellipsize="marquee"
    • android:focusable="true"
    • android:focusableInTouchMode="true"
  2. 如果是多个TextView,在多行,并且内容较多,只设置上面的四个属性就不够了,需要通过以下的方式实现:
    1. 设置不同textview的上面四个属性:
    2. 新建类MarqueeText类继承于TextView,重写三个方法,并且重载isFocused方法如下
      1 @Override
      2     public boolean isFocused() {
      3         // TODO Auto-generated method stub
      4         return true;
      5 };
      isFocused
    3. activity_main.xml文件里面,把控件的类型从TextView改为MarqueeText所在包名.MarqueeText
    4. 在模拟器中显示就可以实现简单的跑马灯效果

 

  1. 类似文章地址1:http://blog.csdn.net/ljw124213/article/details/48352301
  2. 类似文章地址2:http://blog.csdn.net/doris_d/article/details/45056137

posted on 2015-12-21 13:59  csschn  阅读(162)  评论(0)    收藏  举报