本文實現了android系統自帶的跑馬燈效果(marquee)與自定義的跑馬燈效果的對比。
1.在系統自帶的跑馬燈中,xml布局檔案必須配置的屬性有以下幾個:
(1)android:clickable="true"
*(2)android:ellipsize="marquee"
*(3)android:focusable="true"
*(4)android:focusableintouchmode="true"
*(5)android:singleline="true"
這是我寫的(系統自帶)xml布局檔案
2.自定義的跑馬燈
marqueetext類中繼承了textview,在這個類中實現跑馬燈效果
(1)marqueetext類
public class marqueetext extends textview implements runnable
public marqueetext(context context, attributeset attrs)
public marqueetext(context context, attributeset attrs, int defstyle)
@override
protected void ondraw(canvas canvas) }
/*** 獲取文字的寬度
*/private void gettextwidth()
@override
public void run()
postdelayed(this, 5); }
/*** 開始滾動
*/public void startscroll()
/*** 停止滾動
*/public void stopscroll()
/*** 從頭開始滾動
*/public void restartscroll()
}
(2)marqueedemo類
public class marqueedemo extends activity implements onclicklistener
@override
public void onclick(view v)
}}
TextView實現跑馬燈效果
這段 粘上就可用 顯示跑馬燈效果的前提條件就是你的文字內容要比顯示文字的外部元件長,即外部元件無法完整的顯示內部的文字內容。因此要實現跑馬燈效果有兩種設定方式 1 layout width 設定為成比文字內容短的固定值,最好不要寫成wrap content或者fill parent。2 如果layo...
TextView實現跑馬燈效果
一 方法 這裡我們用兩種方法來實現跑馬燈效果,雖然實質上是一種 實質就是 1 textview調出跑馬燈效果 2 textview獲取焦點 第一種 1 textview調出跑馬燈效果 android ellipsize marquee 2 textview獲取焦點 android focusable...
TextView實現跑馬燈效果
一 方法 這裡我們用兩種方法來實現跑馬燈效果,雖然實質上是一種 實質就是 1 textview調出跑馬燈效果 2 textview獲取焦點 第一種 1 textview調出跑馬燈效果 android ellipsize marquee 2 textview獲取焦點 android focusable...