Android跑馬燈效果

jopen 11年前發布 | 31K 次閱讀 Android Android開發 移動開發

當文字內容超過控件內容時,在控件內滾動的效果就是跑馬燈效果。往下主要以TextView為例,EditText,Button類似;

<TextView 
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:textSize="30px"
        android:text="hello,my name is linyuhuan,i am come from canada,where are you come from?"
        android:singleLine="true"       //是否當行顯示文本
        android:ellipsize="marquee"http://文本超過控件長度,如何處理文本內容,此處為滾動動畫顯示
        android:focusable="true"        //是否獲得焦點
        android:focusableInTouchMode="true"    //是否在觸摸模式下獲得焦點
        android:marqueeRepeatLimit="marquee_forever"http://重復滾動的次數
        />

<TextView 

   android:layout_height="wrap_content"    android:layout_width="fill_parent"    android:textSize="30px"    android:text="11111111111111111111111133333333333344444444488888889999999992"    android:singleLine="true"    android:ellipsize="marquee"    android:focusable="true"    android:focusableInTouchMode="true"/>

運行的結果只有第一個有跑馬燈效果。

注意:

(1)Android的缺省行為是在控件獲得Focus時才會顯示走馬燈效果

(2)對于一個大View中有很多子View來說,同一時刻只能有一個子View獲得focus!也就是說當前這一屏上,最多只能有一個view能有跑馬燈效果,而不能多個View同事都有跑馬燈效果。


 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!