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;

 

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