Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 多個 TextView 跑馬燈效果

編輯:關於 Android 程式設計

TextView 的跑馬燈效果常用於顯示過長標題或公告。單一行做起來很簡單,但若畫面上有多個 TextView 都要跑馬燈,就需要多一點技巧。

基本屬性

先設定 android:singleLine=true 讓文字單行顯示,再用 android:ellipsize=marquee 啟動跑馬燈效果,同時讓元件取得焦點,例如設定 focusable 與 focusableInTouchMode。

多個跑馬燈的解法

系統預設通常只會讓一個已取得焦點的 TextView 跑動。若要多個同時跑,可自訂一個繼承 TextView 的類別,並覆寫 isFocused 永遠回傳 true,再把版面中的 TextView 換成這個自訂元件。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved