Android -- textview how to implement unlimited scrolling display

Source: Internet
Author: User

First, you can use textview to implement the Scroll display in the form of a drive lamp. You only need to set two attributes for it:

Android: ellipsize = "marquee" <br/> Android: marqueerepeatlimit = "marquee_forever" <br/> 

However, there is a premise that textview must be in the focus state for the scrolling display of textview. When textview loses focus, textview stops scrolling. To achieve unlimited scrolling, you also need to start with the focus. Of course, direct requestfocus () does not work. Here I use another method. It is observed that textview has a method named isfocused (). The comments in this document are as follows:

/** <Br/> * returns true if this view has focus <br/> * @ return true if this view has focus, false otherwise. <br/> */ 

 

That is to say, true is returned when textview has focus. In addition, in textview, this method is called directly as the judgment condition in many places. The most critical is that this method is declared as public! OK, the implementation method is coming soon!

The method is as follows: Define a ooxxtextview, inherit from textview, and override isfocused () method, and set its return value to true, as shown in the following example:

Public class alwaysmarqueetextview extends textview {<br/> Public alwaysmarqueetextview (context) {<br/> super (context ); <br/>}< br/> Public alwaysmarqueetextview (context, attributeset attrs) {<br/> super (context, attrs ); <br/>}< br/> Public alwaysmarqueetextview (context, attributeset attrs, int defstyle) {<br/> super (context, attrs, defstyle ); <br/>}</P> <p> @ override <br/> Public Boolean isfocused () {<br/> return true; <br/>}< br/>} 

 

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.