欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

android中设置TextView/Button 走马灯(Marquee)效果示例

程序员文章站 2023-08-12 19:21:55
在android的apidemo中,有button的走马灯效果,但是换作是textview,还是有一点差异。 定义走马灯(marquee),主要在project/res/l...
在android的apidemo中,有button的走马灯效果,但是换作是textview,还是有一点差异。
定义走马灯(marquee),主要在project/res/layout/main.xml即可
复制代码 代码如下:

<span style="color: #993300"><textview
android:layout_width="40px"
android:layout_height="wrap_content"
android:text="test marquee for textview"
android:layout_gravity="center"
android:ellipsize="marquee"
android:singleline="true"
android:focusable="true"
android:marqueerepeatlimit="marquee_forever"
android:focusableintouchmode="true"
android:scrollhorizontally="true"
/></span>

关键点:
(1)layout_width设定的长度要比text其实的长度短才行,即layout_width显示不全text才会有走马灯效果 (2)ellipsize 即申明使用走马灯marquee
(3)singleline表示单行显示
(4)marqueerepeatlimit表示走马灯显示的次数:marquee_forever-无限制不间断显示
复制代码 代码如下:

<span style="color: #993300"><button
android:id="@+id/buttonmarquee"
android:layout_width="320px"
android:layout_height="wrap_content"
android:text="@string/textmarquee"
android:singleline="true"
android:focusable="true"
android:selectallonfocus="true"
android:ellipsize="marquee"
android:marqueerepeatlimit="marquee_forever"
/></span>

其中@string/textmarquee为/res/valuse/strings.xml定义的字符串