当前位置: 移动技术网 > 移动技术>移动开发>Android > android中设置TextView/Button 走马灯(Marquee)效果示例

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

2019年07月24日  | 移动技术网移动技术  | 我要评论
在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定义的字符串

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网