csschn

Android,你等等我。。。

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

使用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   csschn  阅读(156)  评论(0编辑  收藏  举报

点击右上角即可分享
微信分享提示