[Android] TextView实现走马灯效果

转自:http://blog.csdn.net/crazyzhangcrazy/article/details/8594991

       在TextViw中,如果文本的长度超出了显示范围,可以使文本水平滚动显示,类似于走马灯的效果,只需在XML布局文件中,为TextView设置如下几个属性即可。

        Android:ellipsize=”marquee”。

        android:marqueeRepeatLimit=”XX”。其中XX表示循环次数,为大于0的整数或marquee_forever(无限循环)。

        android:focusable=”true”。只有处于焦点状态的TextView才能显示走马灯效果。

 

       如下是完整的XML代码

[html] 
view plain
 copy

  1. <?xml version=“1.0” encoding=“utf-8”?>  
  2. <LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”  
  3.     android:orientation=“vertical”  
  4.     android:layout_width=“fill_parent”  
  5.     android:layout_height=“fill_parent”>  
  6.     <TextView android:id=“@+id/textview3”  
  7.         android:layout_width=“fill_parent”  
  8.         android:layout_height=“wrap_content”  
  9.         android:text=“start这里是一个使TextView实现走马灯效果的例子end”  
  10.         android:singleLine=“true”  
  11.         android:ellipsize=“marquee”  
  12.         android:marqueeRepeatLimit=“marquee_forever”  
  13.         android:focusable=“true”  
  14. android:focusableInTouchMode=”true”
  15.         android:background=“#FFF”  
  16.         android:textColor=“#000”  
  17.         android:textSize=“20dp”  
  18.         android:layout_margin=“10dp”  
  19.         android:padding=“10dp”/>  
  20. </LinearLayout>  

        实现效果如下图。

《[Android] TextView实现走马灯效果》

    原文作者:Dijkstra算法
    原文地址: https://blog.csdn.net/bsmmaoshenbo/article/details/61199111
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞