android中设置TextView/Button 走马灯(Marquee)效果示例
更新时间:2013年06月19日 15:33:23 作者:
定义走马灯(Marquee),主要在Project/res/layout/main.xml即可,下面与大家分享下具体的实现,感兴趣的朋友可以参考下哈
在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定义的字符串
定义走马灯(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定义的字符串
相关文章
Android使用ContentProvider实现查看系统短信功能
这篇文章主要为大家详细介绍了Android使用ContentProvider实现查看系统短信功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2021-11-11


最新评论