使用原生的TextView实现“跑马灯”效果,需要特别注意其是否获取到了焦点(特别是程序当中有多个需要赋值的
Textview或进度条之类的需要改变其值的View);TextView只有在获得了焦点的时候才有跑马灯的效果,这样有时候并
不能达到我们所要求的效果。我们可以自定义一个永远已经获取焦点的TextView。
具体代码如下所示。
将自定义的AmMarqueeTextView放到布局文件中,如下所示。
<cn.net.ample.music.view.AmMarqueeTextView
android:id="@+id/tv_music_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="@string/tip_music_name"
android:textColor="@color/grass_green"
android:textSize="@dimen/current_theme_text_size" />