1, implement the custom TextView and implement the IsFocused () method, the code is as follows:
1 Public classRolltextviewextendstextview{2 3 PublicRolltextview (Context context) {4 Super(context);5 }6 PublicRolltextview (Context context, AttributeSet attrs) {7 Super(context, attrs);8 }9 Ten PublicRolltextview (context context, AttributeSet attrs,intDefstyle) { One Super(context, attrs, defstyle); A } - @Override - Public BooleanisFocused () { the return true; - } -}
2, set the Singleline,ellipsize,marqueerepeatlimit property for the custom TextView, and the layout file code is as follows:
1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Android:paddingbottom= "@dimen/activity_vertical_margin"6 Android:paddingleft= "@dimen/activity_horizontal_margin"7 Android:paddingright= "@dimen/activity_horizontal_margin"8 Android:paddingtop= "@dimen/activity_vertical_margin"9 Tools:context=". Mainactivity " >Ten One <com. Tony.test.RollTextView A Android:id= "@+id/tv_test" - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" the Android:singleline= "true" - android:ellipsize= "Marquee" - Android:marqueerepeatlimit= "Marquee_forever" - Android:text= "TextView text scrolling textview text scrolling textview text scrolling textview text scrolling textview text scrolling textview text scrolling" /> + </Relativelayout>
This simple implementation of the text scrolling effect.