The method of realizing the effect of TextView with Android _android

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.