In doing app development, some titles need to achieve the effect of the TextView, if the use of the system with the implementation of this effect, just add the following code in the TextView properties:
Android:ellipsize= "marquee"//Happy Lantern effect
android:marqueerepeatlimit= "Marquee_forever"//Unrestricted uninterrupted display
Android:singleline= "true"//single line display
But there is a fatal drawback, that is, this state of the horse can only be in the focus of the TextView, it will roll, for the actual application of the app development applications is not practical, because it can not always be in the acquisition focus state.
In order to be the happy lights in any case can run up to achieve the desired effect, we need to customize a TextView inheritance TextView, and rewrite the Isfocuse () method, so that it always return true, so that the effect of the horse can always run up.
The code is as follows:
Package Zm.marqueetextview;
Import Android.content.Context;
Import Android.util.AttributeSet;
Import Android.widget.TextView;
public class Marqueetextview extends TextView {
Public Marqueetextview {
Super (context);
}
Public Marqueetextview (context context, AttributeSet Attrs) {
Super (context, attrs);
}
Public Marqueetextview (context context, AttributeSet attrs, int defstyle) {
Super (context, attrs, Defstyle);
}
@Override
public Boolean isfocused () {
return true;
}
}
You can then refer directly to the layout file:
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:padding= "15DP" >
<zm.marqueetextview.marqueetextview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:singleline= "true"
Android:ellipsize= "Marquee"
android:marqueerepeatlimit= "Marquee_forever"
Android:text= "This is a custom TextView with a marquee effect this is a custom TextView with a marquee effect"/>
</RelativeLayout>