android中設(shè)置TextView/Button 走馬燈(Marquee)效果示例
更新時間:2013年06月19日 15:33:23 作者:
定義走馬燈(Marquee),主要在Project/res/layout/main.xml即可,下面與大家分享下具體的實現(xiàn),感興趣的朋友可以參考下哈
在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>
關(guān)鍵點:
(1)layout_width設(shè)定的長度要比text其實的長度短才行,即layout_width顯示不全text才會有走馬燈效果 (2)ellipsize 即申明使用走馬燈marquee
(3)singleLine表示單行顯示
(4)marqueeRepeatLimit表示走馬燈顯示的次數(shù):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即可
復(fù)制代碼 代碼如下:
<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>
關(guān)鍵點:
(1)layout_width設(shè)定的長度要比text其實的長度短才行,即layout_width顯示不全text才會有走馬燈效果 (2)ellipsize 即申明使用走馬燈marquee
(3)singleLine表示單行顯示
(4)marqueeRepeatLimit表示走馬燈顯示的次數(shù):marquee_forever-無限制不間斷顯示
復(fù)制代碼 代碼如下:
<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定義的字符串
相關(guān)文章
Android 網(wǎng)絡(luò)圖片查看器與網(wǎng)頁源碼查看器
本篇文章主要介紹了Android 網(wǎng)絡(luò)圖片查看器與網(wǎng)頁源碼查看器的相關(guān)知識。具有很好的參考價值。下面跟著小編一起來看下吧2017-04-04
Android使用ContentProvider實現(xiàn)查看系統(tǒng)短信功能
這篇文章主要為大家詳細介紹了Android使用ContentProvider實現(xiàn)查看系統(tǒng)短信功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-11-11
Android 優(yōu)化之存儲優(yōu)化的實現(xiàn)
這篇文章主要介紹了Android 優(yōu)化之存儲優(yōu)化的實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-07
Android橫豎屏切換及其對應(yīng)布局加載問題詳解
這篇文章主要為大家詳細介紹了Android橫豎屏切換及其對應(yīng)布局加載問題,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-04-04
Android通過手機拍照或從本地相冊選取圖片設(shè)置頭像
微信、QQ、微博等社交類APP如何更換自己的頭像,這篇文章主要介紹了Android通過手機拍照或從本地相冊選取圖片設(shè)置頭像,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07
Jetpack Compose實現(xiàn)動畫效果的方法詳解
compose為支持動畫提供了大量的 api,通過這些 api 我們可以輕松實現(xiàn)動畫效果。本文將為大家介紹利用compose實現(xiàn)的多種動畫效果的示例代碼,需要的可以參考一下2022-02-02
Android開發(fā)優(yōu)化之Apk瘦身優(yōu)化指南
隨著業(yè)務(wù)快速發(fā)展,各種業(yè)務(wù)功能上線,版本不斷迭代,apk體積也越來越大,下面這篇文章主要給大家介紹了關(guān)于Android開發(fā)優(yōu)化之Apk瘦身優(yōu)化的相關(guān)資料,需要的朋友可以參考下2022-05-05

