Facebook open-source Shimmer, a loading effect tool, enables the font to shine as follows:
The link here is ghost (no object-c, ghost ZR), so I searched Shimmer android. Someone actually did it. Here, https://github.com/romainpiel/shimmer-android. The following is
VcnBtq + release/Y1sajrM/Cw + a + zcC01/release + release = "brush: java;"> public class MyTextView extends TextView {private LinearGradient mLinearGradient; private Matrix mGradientMatrix; private Paint mPaint; private int mViewWidth = 0; private int mTranslate = 0; private boolean mAnimating = true; public MyTextView (Context context, AttributeSet attrs) {super (context, attrs) ;}@ Overrideprotected void onSizeChanged (int w, int h, int oldw, int oldh) {super. onSizeChanged (w, h, oldw, oldh); if (mViewWidth = 0) {mViewWidth = getMeasuredWidth (); if (mViewWidth> 0) {mPaint = getPaint (); mLinearGradient = new LinearGradient (-mViewWidth, 0, 0, 0, new int [] {0x33ffffff, 0 xffffffff, 0x33ffffff}, new float [] {0, 0.5f, 1}, Shader. tileMode. CLAMP); mPaint. setShader (mLinearGradient); mGradientMatrix = new Matrix () ;}}@ Overrideprotected void onDraw (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 );}}}
Inherit a TextView. Because the gradient translation requires the width of the view, each required element is initialized in onSizeChanged, and the color and position of the gradient are defined in linearGradient, then set the paint for the drawing. The onDraw () method controls the calculation of the Offset. Here, the draw time of each frame is set in every 1/10 of the moving width and postInvalidateDelay (), that is, the speed of the flashing is controlled. The effect is as follows: