Android custom view border text, flashing text
Extend existing controls
1. Draw a textview with two layers of background as shown below
Create bordertextview inherit textview
Initialize some basic data in the constructor
Override the OnDraw () method, in which the canvas object is mainly used to draw.
If you run after the above, you will find that the text cannot be fully displayed because the size of the text itself does not change after we pan the text, resulting in incomplete text display. We need to overload the onmeasure() method to recalculate the width and height of the textview.
Summary: 1. The onmeasure () method is used to determine the size of the control, and the OnDraw () method is used to draw. 2. Setmeasureddimension (width, height) sets the width and height of the control
2. Flashing text
This implementation mainly changes the color by linearly rendering the object.
Initialize in the onsizechanged() method.
Get the size of our text, get the paint object of the text, and initialize the LinearGradient object.
Create a LinearGradient and set the gradient color array
Initialize the matrix object. This object is mainly used to change the value of the renderer. Please see this blog for details http://blog.csdn.net/flash129/article/details/8234599
Change the matrix object in the OnDraw () method and set it to the renderer. At the same time, refresh the attempt to form a loop.
Summary: 1. Set the gradient of the image through LinearGradient. 2. The matrix changes the translation object of the gradient. The source code of the custom view has been uploaded to GitHub. If you need the source code, please move to https://github.com/AlexSmille/CustomView
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.