Android下Button/TextView 走马灯效果

2014-11-24 09:04:42 ? 作者: ? 浏览: 0

定义走马灯(Marquee),主要在Project/res/layout/main.xml即可(当然也可以是其它名字的.xml,main.xml是系统默认,习惯了而已)


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-无限制不间断显示


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


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


-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: