Android Glitter Font effect

Source: Internet
Author: User

Original:

http://blog.csdn.net/xu_fu/article/details/24484019

ImportAndroid.content.Context;ImportAndroid.graphics.Canvas;Importandroid.graphics.LinearGradient;ImportAndroid.graphics.Matrix;ImportAndroid.graphics.Paint;ImportAndroid.graphics.Shader;ImportAndroid.util.AttributeSet;ImportAndroid.widget.TextView; Public classShinetextviewextendsTextView {Privatelineargradient mlineargradient; PrivateMatrix Mgradientmatrix; PrivatePaint Mpaint; Private intMviewwidth = 0; Private intMtranslate = 0; Private BooleanManimating =true;  PublicShinetextview (Context context, AttributeSet attrs) {Super(context, attrs); } @Overrideprotected voidOnsizechanged (intWintHintOLDW,intOLDH) {          Super. Onsizechanged (W, H, OLDW, OLDH); if(Mviewwidth = = 0) {Mviewwidth=getmeasuredwidth (); if(Mviewwidth > 0) {Mpaint=Getpaint (); //Create a LinearGradient object//starting point coordinates (-mviewwidth, 0) endpoint coordinates (0,0)//first, the second parameter indicates that the starting point of the gradient can be set at any position in the diagonal.//Third, the fourth parameter represents the end of the gradient//The fifth parameter represents a gradient color//The sixth parameter can be empty, representing coordinates, and a value of 0-1, if this is empty, the color is evenly distributed along the gradient line. //The seventh one means tiling//clamp Repeat last color to last//Mirror Duplicate-shaded images are mirrored in the horizontal or vertical orientation of the fill will have a rollover effect//repeat the horizontal or vertical orientation of the image for repeated coloringMlineargradient =NewLinearGradient (-mviewwidth, 0,                         0, 0,                          New int[] {0xff0288da, 0xFFFFFFFF, 0xff0288da },                        New float[] {0, 0.5f, 1}, Shader.TileMode.CLAMP);                  Mpaint.setshader (mlineargradient); Mgradientmatrix=NewMatrix (); } }} @Overrideprotected voidOnDraw (canvas canvas) {Super. OnDraw (canvas); if(manimating && Mgradientmatrix! =NULL) {mtranslate+ = MVIEWWIDTH/10; if(Mtranslate > 2 *mviewwidth) {Mtranslate= -Mviewwidth; } mgradientmatrix.settranslate (Mtranslate,0);              Mlineargradient.setlocalmatrix (Mgradientmatrix); Postinvalidatedelayed (50); }      }  }

Android Glitter Font effect

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.