先新建一个继承textview的MarqueeText的类
public class MarqueeText extends TextView {
public MarqueeText(Context context) {
super(context);
}
public MarqueeText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarqueeText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean isFocused() {
return true;
}
}
然后引用这个类创建textview
<com.example.chris.paomadengtextview.MarqueeText
android:id="@+id/textview1"
android:text="@string/hello_world"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:ellipsize="marquee" />
<com.example.chris.paomadengtextview.MarqueeText
android:id="@+id/textview2"
android:layout_below="@+id/textview1"
android:layout_marginTop="10dp"
android:text="@string/hello_world"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:ellipsize="marquee" />