做以下设置指定就有跑马灯效果了,要文字超出text宽度才有:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.zhouyi.textviewrun.MainActivity"> <TextView android:layout_width="100dp" android:layout_height="wrap_content" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:focusableInTouchMode="true" android:focusable="true" android:scrollHorizontally="true" android:text="这才是真正的文字跑马灯效果" /> </RelativeLayout>