This article is for you to share a very simple but very commonly used control, the textview of the status of the horse lamp. When the length of the text to display is too long, and do not want to change lines to display text, you can completely display the text, and the effect is very cool, to achieve a super simple, so, he le. First look at the effect of the picture:
Code implementation
TextView with the function of the horse, as long as its Ellipsize property set to marquee on it. But there is a premise, is textview to be in the selected state to have effect, see this, we are very natural custom a control, write the following code:
public class Marqueetextview extends TextView {public
marqueetextview (context con) {
super (con);
}
Public Marqueetextview (context, AttributeSet attrs) {
Super (context, attrs);
}
Public Marqueetextview (context, AttributeSet attrs, int defstyle) {
Super (context, attrs, Defstyle);
}
@Override Public
boolean isfocused () {
//TODO auto-generated method Stub
if (Geteditabletext). Equals (Truncateat.marquee)) {return
true;
}
return super.isfocused ();
}
Rewrite the isfocused method, and make a judgment that only the Marqueen property is set to remain selected, otherwise it will be the same as normal TextView. Then you can use it directly and look at the layout:
<linearlayout xmlns: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 "Android:o" rientation= "vertical" > <framelayout android:id= "@+id/titlebar_layout" android:layout_width= "Match_parent" an droid:layout_height= "Wrap_content" android:background= "#39ac69" > <linearlayout android:layout_width= "Match_" Parent "android:layout_height=" 50DP "android:background=" "#ffffff" android:gravity= "center_vertical" Android:or ientation= "Horizontal" > <imageview android:id= "@+id/home_location_iv" android:layout_width= "25DP" a ndroid:layout_height= "27DP" android:layout_marginleft= "10DP" android:scaletype= "Fitxy" android:src= "@drawable Icon_place "/> <com.lxj.marqueetextview.marqueetextview android:id=" @+id/home_location_tv "Android:layou"
T_width= "0DP" android:layout_height= "Wrap_content"android:layout_marginleft= "10DP" android:layout_marginright= "10DP" android:layout_weight= "1" android:ellipsize = "Marquee" android:focusable= "true" android:focusableintouchmode= "true" android:gravity= "center" android:m arqueerepeatlimit= "Marquee_forever" android:scrollhorizontally= "true" android:singleline= "true" android:text= Positioning ... "android:textcolor=" #39ac69 "android:textsize=" 18sp "/> <imageview android:id=" @+id/home_sea Rch_iv "android:layout_width=" 25DP "android:layout_height=" 27DP "android:layout_marginright=" 10DP "Android : scaletype= "Fitxy" android:src= "@drawable/icon_place"/> </LinearLayout> </FrameLayout> </linearl
Ayout>
Note that the two-point Ellipsize property is set to "marquee", and the line number property is Singleline to set to true. To this textview the effect of the horse will be achieved.
I hope this article will help you learn about Android software programming.