TextView实现滚动播放

首先,对于TextView来说,只有在内容超出能够显示的范围,才会需要滚动播放。


所以,我们要做的第一步就是设置范围:

android:singleLine="true"
设置单行显示,如果不设置 singleLine或者说设置 singleLine="false",TextView中的内容在满一行后就会自动换行。


接下来自然就会想到,我们既然设置了单行显示,那么超出的部分会怎么样呢?

那就要通过 android:ellipsize 这个属性来实现了:

android:ellipsize="start" -- <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">省略号在开头</span>

       

android:ellipsize="middle" -- <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">省略号在中间</span>

       

android:ellipsize="end"  -- <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">省略号在结尾</span>

       

android:ellipsize="marquee"  -- <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">跑马灯显示</span>

或者在程序中可通过setEillpsize显式设置。(注意:EditText不支持marquee这种模式

如果设置了 marquee模式(跑马灯显式),就要记得设置 android:marqueeRepeatLimit 属性,也就是设置重复滚动的次数,当设置为marquee_forever时表示无限次。


最最重要的就是 android:focusable 属性(能否获得焦点),记得要设置为true;focusableInTouchMode是滑动时能否获得焦点,也要设置为true。


<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:singleLine="true"
        android:focusable="true"
        android:text="dsadsakdhsajkhasdsad asd23a d132sa1d32as1d56sa4d65sa4d65sa465d4sadjksa"/>






  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值