Flip through git --- the TextView RevealTextView of the flashing Animation

Source: Internet
Author: User

Flip through git --- the TextView RevealTextView of the flashing Animation

A text view that flashes on its own today to attract user attention* RevealTextView *

First up and down: (this picture is big enough)

How to use?

Gradle

dependencies {  compile 'com.antonionicolaspina:revealtextview:2.0'}

Eclipse
Copy attires. xml and RevealTextView. java.

Next, let's take a look at the things of the custom Styleable. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwcmUgY2xhc3M9 "brush: java; "> <code class =" hljs xml "> <declare-styleable name =" RevealTextView "> <attr format =" integer "name =" rtv_duration "> <attr name =" android: text "> </attr> </declare-styleable> </code>

Only the duration and text

Next, let's look at the specific implementation

public final class RevealTextView extends TextView implements Runnable, ValueAnimator.AnimatorUpdateListener

It inherits the time when TextView implements multithreading and animation. At first glance, it can be seen that it does not use Handler implementation. The pure main thread and sub-thread operations work with the animation to achieve the flickering effect.

  protected void init(TypedArray attrs) {    try {      animationDuration = attrs.getInteger(R.styleable.RevealTextView_rtv_duration, animationDuration);      text = attrs.getString(R.styleable.RevealTextView_android_text);    } finally {      attrs.recycle();    }    setAnimatedText(text);  }

The next step is initialization, and the next step is to call the operation to start the animation. Here, the words sent from the tag are sent.

public void setAnimatedText(String text) {    this.text = text;    alphas    = new double[text.length()];    for(int i=0; i
  

Here, we use an array as the container of the entire string, and then generate a random number for each character into the container, and then start the multi-thread operation.

public void replayAnimation() { if (null != text) { post(this); } }

When the string is not empty, multi-threaded operations are started.

The two methods are public and are called externally.

 @Override public void run() { final int color = getCurrentTextColor(); red = Color.red(color); green = Color.green(color); blue = Color.blue(color); ValueAnimator animator = ValueAnimator.ofFloat(0f, 2f); animator.setDuration(animationDuration); animator.addUpdateListener(this); animator.start(); }

Initialize the animation in the run method.

 @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { final float value = (float) valueAnimator.getAnimatedValue(); SpannableStringBuilder builder = new SpannableStringBuilder(text); for(int i=0; i 

The font is processed twice in onAnimationUpdate to achieve the effect in the graph.

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.