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

被折叠的 条评论
为什么被折叠?



