TextView 实现跑马灯效果

时间:2023-01-24 22:49:50

在String.xml中添加:

<string name="txt">跑马灯效果,我跑啊跑</string>
在layout/mian.xml中添加TextView:
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:text="@string/txt" />

最后在mainActivity.java中添加一个属性:
//跑马灯效果
TextView tv = (TextView) findViewById(R.id.textView);
tv.setSelected(true);