Android TextView Marquee Effect

Source: Internet
Author: User

TextView Simple Effect
<!--Simple example-<TextView Android:text="@string/longword"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:id="@+id/textview1"android:ellipsize="Marquee"Android:singleline="true"android:focusable="true"Android:focusableintouchmode="true"/>


TextView a few of the common properties of the marquee effect, of which ellipsize, Singleline, focusable, Focusableintouchmode are required, and other optional

<!--active Focus--android:focusable="true"<!--single-line display-Android:singleline="true"<!--This is set to scroll beyond the text after the display-android:ellipsize="Marquee"<!--This is set to scroll several times, here is an infinite loop--Android:marqueerepeatlimit="Marquee_forever"<!--touchmode mode focus activated--Android:focusableintouchmode="true"< whether there is a horizontal scroll bar when the!--is out of horizontalandroid:scrollhorizontally="true"


Here is a textview the effect seems to be OK, but the layout of the page is generally very complex, sometimes a page may have more than a marquee effect, here if we put two or more textview, then the effect of the marquee?

Here we will write a textview look at the effect, from which we can see that two of the same textview, found that the first one is the effect of the lantern, and the second is not, what is the situation?

Through the almighty Baidu, we learned that TextView default is the first to get the cursor, and the back TextView is not get to the cursor, and the marquee effect is needed to get to the cursor, here we know why, then to expand the TextView, let all the

TextView gets to the cursor.

TextView Extended Marquee effect

1, the first to build a MarqueeText Java class, and this class inherits TextView

2. MarqueeText implements three constructors for TextView, and overloads the Isfoused () method

/*** Created by Darren on 2015/2/23. * Set all the TextView have a marquee effect*/ Public classMarqueeTextextendsTextView { PublicMarqueeText (Context context) {Super(context); }     PublicMarqueeText (Context context, AttributeSet attrs) {Super(context, attrs); }     PublicMarqueeText (context context, AttributeSet attrs,intdefstyleattr) {        Super(context, attrs, defstyleattr); }    //The textview default setting is the first cursor that gets to the//If you want all the TextView to have a marquee effect, let all the TextView get to the cursor.//This return true is to get all the TextView to the cursor@Override Public BooleanisFocused () {return true; }}
View Code


3, in the design page we changed the TextView to MarqueeText

<TextView Android:text= "@string/longword"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:id= "@+id/textview1"android:ellipsize= "Marquee"Android:singleline= "true"android:focusable= "true"Android:focusableintouchmode= "true"/> <Sh.geeko.marqueetext.marqueeText android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:id= "@+id/textview2"Android:text= "@string/longword"Android:layout_below= "@id/textview1"Android:layout_margintop= "20DP"android:ellipsize= "Marquee"Android:singleline= "true"android:focusable= "true"Android:focusableintouchmode= "true"/>
View Code

Here we look at the specific implementation effect:

SOURCE download

Android TextView Marquee Effect

Related Article

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.