First, the introduction of the problem
Using the normal TextView horse racing effect, initially no focus events will not scroll, the button has focus events, but it is ugly, so you need to customize a TextView born with focus
Then you need to customize a TextView
Focusedtextview.java
PackageCom.xuliugen.mobilesafe.ui;ImportAndroid.content.Context;ImportAndroid.util.AttributeSet;ImportAndroid.view.ViewDebug.ExportedProperty;ImportAndroid.widget.TextView;/** * Happy horse effect, start without focus event will not scroll * * Button has focus event, but it is ugly, so you need to customize a textview born with Focus * * @author Xuliugen * */ Public class focusedtextview extends TextView { /** * Custom view requires the following construction methods * * @param context * @param attrs * @param de Fstyle * * Public Focusedtextview(context context, AttributeSet attrs,intDefstyle) {Super(Context, attrs, Defstyle); } Public Focusedtextview(context context, AttributeSet attrs) {Super(context, attrs); } Public Focusedtextview(Context context) {Super(context); }/** * Currently there is no focus, I just lied to the Android system */ @Override @ExportedProperty(category ="Focus") Public Boolean isFocused() {return true; }}
Then we quote the following:
<!-- 跑马灯的效果 :滚动的textView--> <com.xuliugen.mobilesafe.ui.FocusedTextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:ellipsize="marquee" android:singleLine="true" android:text="自定义TextView使之具有跑马灯的效果自定义TextView使之具有跑马灯的效果自定义TextView使之具有跑马灯的效果" android:textSize="18sp" />
Customize the TextView to have a marquee effect