TextView跑马灯效果

本文介绍了如何在Android中使用TextView实现跑马灯效果。通过设置特定属性如android:ellipsize=marquee和android:marqueeRepeatLimit=marquee_forever等,可以轻松创建无限滚动的文字显示。此外,还提供了示例代码帮助理解。

1、         Textview跑马灯效果:

                       

实现起来比较简单,只需对Textview控件添加如下属性:

        android:ellipsize="marquee"

        android:focusable="true"

        android:focusableInTouchMode="true"

        android:marqueeRepeatLimit="marquee_forever"

        android:scrollHorizontally="true"

android:ellipsize:

设置当文字过长时,该控件该如何显示。有如下值设置:”start”—–省略号显示在开头;”end”——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动)

android:marqueeRepeatLimit:

在ellipsize指定marquee的情况下,设置重复滚动的次数,当设置为marquee_forever时表示无限次

android:scrollHorizontally:设置文本超出TextView的宽度的情况下,是否出现横拉条。

android:focusableInTouchMode:触摸获取焦点

源码:

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:text="在那个古老的不再回来的夏日,   无论我如何地去追索 "
        android:textColor="#ff0000"
        android:textSize="20dp" >
    </TextView>


  
  
  
  
  
  
  
 
 
 



 
  
  
  
  
  
  
  
  
  
  
  
  
 
 
 


转载于:https://www.cnblogs.com/ouyangxiaoqing/archive/2013/01/22/2871311.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值