TextView v=new TextView(this);
v.setText("哇哈哈哇哈哈哇哈哈哇哈哈哇哈哈wahahawahhahwahhahahwahahhahahawhahhaha......");
v.setTransformationMethod(SingleLineTransformationMethod.getInstance());
v.setSingleLine(true);
v.setEllipsize(TruncateAt.MARQUEE);
v.setMarqueeRepeatLimit(3);
setContentView(v);
v.setFocusable(true);
或者在xml文件中声明
<TextView
android:id="@+id/text"
android:layout_width="100px"
android:layout_height="wrap_content"
//居中显示
android:layout_centerInParent="true"
//使得字不分行显示 否则当字太多会分行
android:singleLine="true"
android:layout_x="61px"
android:layout_y="69px"
//设置为"滚动"
android:ellipsize="marquee"
//设置滚动时间为永远 也可以为具体的int 来设置滚动次数
android:marqueeRepeatLimit="marquee_forever"
/>