展会信息港展会大全

android中设置TextView/Button 走马灯效果
来源:互联网   发布日期:2015-11-25 22:12:01   浏览:2542次  

导读:在Android的ApiDemo中,有Button的走马灯效果,但是换作是TextView,还是有一点差异。騀义走马灯(Marquee),主要在Project/res/layout/m...

在Android的ApiDemo中,有Button的走马灯效果,但是换作是TextView,还是有一点差异。

定义走马灯(Marquee),主要在Project/res/layout/main.xml即可

[html]

<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>

<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"

/>

关键点:

(1)layout_width设定的长度要比text其实的长度短才行,即layout_width显示不全text才会有走马灯效果

(2)ellipsize 即申明使用走马灯marquee

(3)singleLine表示单行显示

(4)marqueeRepeatLimit表示走马灯显示的次数:marquee_forever-无限制不间断显示

[html]

<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>

<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"

/>

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港