Android custom controls create glittering fonts
introduce
In Xiaomi's startup animation and some welcome interfaces, we often see this glittering streamer font. It looks cool. In fact, the implementation principle is quite simple. We just need to write a custom control to inherit textview, then use the renderer gradient to set the color gradient and the setshadowlayer method of paint to set the shadow, and then constantly refresh and change the displacement.
realization
First write a shinetextview class that inherits from textview
In this code, we define two color renderers
LinearGradient is a linear gradient rendering, and the gradient representing the color changes in a linear direction. We can use LinearGradient to achieve the effect in the second figure above
RadialGradient is a circular gradient rendering, and the gradient representing the color changes in a circular ring.
We can use radiogradient to achieve the effect of Xiaomi startup animation in the first picture above.
We make the color change dynamically by controlling the brightness displacement distance of mtranslate.
OnSizeChanged
In the onsizechange method, we mainly complete some initialization operations, such as obtaining the width and height of the control, initializing the color renderer and setting the font shadow effect.
onDraw
In the last step, we only need to draw the effect in the OnDraw method and shift the gradient effect through the matrix matrix.
Source code download: http://xiazai.jb51.net/201701/yuanma/AndroidShineText (jb51.net).rar
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.