普通的跑馬燈效果只要在textview加上這幾個屬性一般就ok了
android:singleline="true"
android:ellipsize="marquee"
android:scrollhorizontally="true"
android:marqueerepeatlimit="marquee_forever"
android:focusableintouchmode="true"
android:focusable="true"
但是如果你的頁面中有edittext 或者其他能讓 跑馬燈失去焦點的控制項,當這些控制項獲得focus之後,就會發現跑馬燈不跑了.
解決辦法為重寫onfocus方法:
public marqueetextview(context context)
public marqueetextview(context context, attributeset attrs)
public marqueetextview(context context, attributeset attrs, int defstyleattr)
//重寫isfocused方法,讓其一直返回true
public boolean isfocused()
@override
public onfocuschangelistener getonfocuschangelistener()
@override
public void onwindowfocuschanged(boolean haswindowfocus)
}這樣你的跑馬燈就不會受到其他控制項的影響,一直奔跑起來了
TextView 跑馬燈效果
本文實現了android系統自帶的跑馬燈效果 marquee 與自定義的跑馬燈效果的對比。1.在系統自帶的跑馬燈中,xml布局檔案必須配置的屬性有以下幾個 1 android clickable true 2 android ellipsize marquee 3 android focusable...
TextView實現跑馬燈效果
這段 粘上就可用 顯示跑馬燈效果的前提條件就是你的文字內容要比顯示文字的外部元件長,即外部元件無法完整的顯示內部的文字內容。因此要實現跑馬燈效果有兩種設定方式 1 layout width 設定為成比文字內容短的固定值,最好不要寫成wrap content或者fill parent。2 如果layo...
TextView實現跑馬燈效果
一 方法 這裡我們用兩種方法來實現跑馬燈效果,雖然實質上是一種 實質就是 1 textview調出跑馬燈效果 2 textview獲取焦點 第一種 1 textview調出跑馬燈效果 android ellipsize marquee 2 textview獲取焦點 android focusable...