布局文件
<LinearLayout 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:orientation ="vertical"
tools:context =".MainActivity" >
<com.example.textview.MarqueeText
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:ellipsize ="marquee"
android:focusable ="true"
android:focusableInTouchMode ="true"
android:singleLine ="true"
android:text ="@string/hello_world" />
<com.example.textview.MarqueeText
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:ellipsize ="marquee"
android:focusable ="true"
android:focusableInTouchMode ="true"
android:singleLine ="true"
android:text ="@string/hello_world" />
</LinearLayout >
自定义类
package com.example.textview;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class MarqueeText extends TextView {
public MarqueeText (Context context) {
super (context);
}
public MarqueeText (Context context, AttributeSet attrs, int defStyle) {
super (context, attrs, defStyle);
}
public MarqueeText (Context context, AttributeSet attrs) {
super (context, attrs);
}
@Override
public boolean isFocused () {
return true ;
}
}