TextView realize the effect of the marquee:
Example one:
This example can be solved to a textview realize the effect of the marquee, but can not solve all the textview to achieve the effect of the marquee.
< textview android:layout_width = "Wrap_content" = "Wrap_content" = "true" Android: Ellipsize = "marquee" android:focusable = "true" android:focusableintouchmode< /span>= "true" Android:text = "The function of this project is to make this single line of a long and long single row of TextView realize the effect of the marquee ... " />
But this method can not give two textview at the same time to achieve the effect of the textview when there are two.
The reason is that textview default isfocused () method can only be implemented focused for an object.
The workaround is to create a new class Marqueetextview inherit TextView and let his isfocused () method return True. (Note: Subclass Marqueetextview needs to implement all 3 constructors of the parent class, otherwise there will be a problem).
PackageCom.example.textviewhorseracelamp;ImportAndroid.content.Context;ImportAndroid.util.AttributeSet;ImportAndroid.widget.TextView; Public classMarqueetextviewextendsTextView { PublicMarqueetextview (Context context) {Super(context); //TODO auto-generated Constructor stub } PublicMarqueetextview (context context, AttributeSet attrs,intDefstyle) { Super(context, attrs, Defstyle); //TODO auto-generated Constructor stub } PublicMarqueetextview (Context context, AttributeSet attrs) {Super(context, attrs); //TODO auto-generated Constructor stub} @Override Public BooleanisFocused () {return true; }}
Marqueetextview.java
<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" > <Com.example.textviewhorseracelamp.MarqueeTextViewAndroid:id= "@+id/textview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:singleline= "true"android:ellipsize= "Marquee"android:focusable= "true"Android:focusableintouchmode= "true"Android:text= "The purpose of this project is to make this single line of long, long, separate lines of TextView realize the effect of the marquee ... " /> <Com.example.textviewhorseracelamp.MarqueeTextViewAndroid:id= "@+id/textview2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_margintop= "20DP"Android:singleline= "true"android:ellipsize= "Marquee"android:focusable= "true"Android:focusableintouchmode= "true"Android:text= "The purpose of this project is to make this single line of long, long, separate lines of TextView realize the effect of the marquee ... " /></Relativelayout>
Activity_main.xml
Effect:
Added: pixels
PX cannot be scaled according to resolution
Dp,sp,dip can be scaled based on resolution (now DP as standard)
SP more used in the text zoom
Android TextView realizes the marquee