Android Custom TextView Marquee Monitor

Source: Internet
Author: User

TextView all have run lanterns effect, if say let you go to monitor the performance of the Lantern, I think this demand a bit two, but also to achieve. Ideas: 1. Customizing view inheritance TextView This method is too cumbersome, just listening to a marquee. 2. Customize the span. Easy to use, extend the functionality of TextView.
The key code is as follows:
@Override     public void draw (canvas canvas, charsequence text, int start, int end,   & nbsp;        float x, int top, int y, int bottom, paint paint) {   &nbs p;    canvas.save ();        Canvas.drawtext (text.toString (), X- StartX, y, paint);        Canvas.restore ();         int measuretext = (int) paint.measuretext (text, 0, text.length ());         if (valueanimator = = null) {            InitAnimator ( Measuretext-mview.getwidth ());       }   }      private int startX = 0;    private final static int defult_duration =;    Priv ate int duration = defult_duration;    @Override     public int GetSize (paint paint, charsequence text, int start, int end,      & nbsp;     fontmetricsint FM) {        return 40;    }     private void initanimator (int width) {              valueanimator = valueanimator.ofint (0, width, 0);              Valueanimator.addupdatelistener (New Animatorupdatelistener () {                 @Override                  public void Onanimationupdate ( Valueanimator animation) {                     StartX = (Integer) animation.getanimatedvalue ();                     mView.invalidate ();                }            });              Valueanimator.setinterpolator (New Linearinterpolator ());              valueanimator.setduration (Duration);              Valueanimator.addlistener (New Animatorlisteneradapter () {                  @Override                  public void Onanimationrepeat (Animator Animation) {                     if (Measyspanlistener! = null) {                         Measyspanlistener.over ();                    }                }            });             Valueanimator.setrepeatcount (Integer.max_value);              Valueanimator.start ();    }


span itself is a function enhancement to textview. Use:  string Text = "This is used to test the textview of the marquee effect, want to listen to his run out of events with." ";        spannablestring spannablestring = new Spannablestring (text);         Easyspan easyspan  =new easyspan (mainactivity.this,test);         easyspan.setduration (10000);        Easyspan.seteasyspanlistener (New Easyspanlistener () {             @Override             public void over () {                 log.i ("Test", "over");            }       } );        Spannablestring.setspan (easyspan, 0, Text.length (), Spannable.SPAN_ inclusive_inclusive);         Test.settext (spannablestring);  
Very simple small function, everyone read the code bar. Source: Https://github.com/flyme2012/EasyListenerSpan

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Custom TextView Marquee Monitor

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.