TextView ellipsize=“marquee” 跑马灯效果不能实现,解决

在TextView 添加了

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:textSize="20sp"
        android:text="Medium Text1,Medium Text2,Medium Text3,Medium Text4,Medium Text5,Medium Text6,Medium Text7" />


在部署应用后并不能实现效果,而是显示一行后,其余被截断并渐隐

查找后最简单的解决方法是添加一句 android:textIsSelectable="true" 即可触发跑马灯效果。

或者添加:android:focusable="true"
            android:focusableInTouchMode="true"

目的都是使该控件获得焦点。

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textIsSelectable="true"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:textSize="20sp"
        android:text="Medium Text1,Medium Text2,Medium Text3,Medium Text4,Medium Text5,Medium Text6,Medium Text7" />


效果图:



在虚拟机4.4.4上测试,两种均可显示,在真机6.0测试,android:textIsSelectable="true" 会出现循环播放,但文字内容不完全显示问题。


猜你喜欢

转载自blog.csdn.net/ganfanzhou/article/details/50009479