It is still relatively simple to realize the marquee.
At the same time there are several points to note, first on the code:
1 Public classMtviewextendsTextView {2 3 4 PublicMtview (Context context) {5 Super(context);6 }7 8 PublicMtview (Context context, AttributeSet attrs) {9 Super(context, attrs);Ten } One A PublicMtview (context context, AttributeSet attrs,intdefstyleattr) { - Super(context, attrs, defstyleattr); - } the - PublicMtview (context context, AttributeSet attrs,intDefstyleattr,intdefstyleres) { - Super(context, attrs, defstyleattr); - } + - @Override + Public BooleanisFocused () { A return true; at } -}
1 <Me.fwl.MTView2 Android:layout_width= "120DP"3 Android:layout_height= "20DP"4 android:layout_centerinparent= "true"5 android:ellipsize= "Marquee"6 android:gravity= "Center_vertical"7 Android:singleline= "true"8 Android:marqueerepeatlimit= "Marquee_forever"9 Android:text= "The easiest way to implement a marquee in Android rewrite TextView" />
It is important to note that:
1,ellipsize, this property indicates how long the time to handle, start means only the beginning, middle means to intercept the middle of a paragraph, end to take the following paragraph, marquee means the scroll effect of the Marquee
2,singleline, this property is required to be set. If you can do more, how do you run? You can use your toes to understand.
3,marqueerepeatlimit, which represents the number of repetitions, can be passed directly to the value of an int. The incoming Marquee_forever and 1 represent an infinite loop.
4, to get the focus, here is to override TextView's Isfocus () method to control its focus, and the XML can also be set to get focus, but you can't guarantee to be taken away by someone else, so, to rewrite.
Android-textview Marquee Effect