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