跑马灯

第一种方式:

public class FocusedTextView extends TextView {

public FocusedTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public FocusedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public FocusedTextView(Context context) {
super(context);
}

@Override
public boolean isFocused() {
return true;
}

}

<com.itheima.mobilesafe.ui.FocusedTextView
android:id="@+id/tv_home_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#ff0000"
android:ellipsize="marquee"
android:text="我是您的手机安全卫士,我时刻的保护您的手机安全,哈哈哈,嘎嘎嘎嘎.嘿嘿嘿"
/>

第二种方式:设置textview的四个属性为true即可

android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"

原文地址:https://www.cnblogs.com/bravolove/p/4988173.html