TextView實現跑馬燈

 <TextView
        android:text="@string/ch_hello"
        android:id="@+id/TextView01"
        android:layout_width="320px"
        android:layout_height="wrap_content"
        android:textColor="@color/blue"
        android:ellipsize="marquee"
        android:focusable="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:focusableInTouchMode="true"
        android:scrollHorizontally="true"
        style="@style/big_font"
        />

這種方法實現的跑馬燈只有在當前TextView處於焦點狀態纔有效果,因此可用於一些字符串比較長的焦點顯示項;

android:focusableInTouchMode="true" 是關鍵語句,

橫向字符串要比android:layout_width寬,否則現有的寬度就能完全顯示字符串,也就不需要滾動顯示了;

android:ellipsize 的value有:“start”字符串開頭顯示省略號;

                                               “middle”字符串中間顯示省略號;

                                                “end”字符串結尾顯示省略號;

                                                “marquee”字符串跑馬燈顯示;

android:id="@+id/TextView01"  //爲TextView添加一個ID標識,便於Java代碼通過R類來訪問該TextView;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章