對於長文本的顯示,除了用省略號之外我們還可以讓它滾動顯示,這樣的效果也叫走馬燈效果 !
我們實現這個效果,也要用到上面android:ellipsize的屬性,還有android:marqueeRepeatLimit,和android:focusable屬性:
<TextView android:id="@+id/txtInfo" android:text="這裏是測試內容,內容要長容要長要長長長長長長長長長長長長長長長長" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:focusable="true" android:focusableInTouchMode="true" android:singleLine="true" android:layout_width="fill_parent" android:layout_height="wrap_content" />
如果有的朋友實現這個走馬燈效果時發現它跑不起來,記得把android:focusableInTouchMode事件也寫上就行了。