The first time to write with pictures of the blog, how much is still a little nervous, the effect is not good, please see, the previous figure is today to write the control of the effect diagram, the elements are not many, respectively, is a button and a custom control.
Before this, I read a lot of books, such as "Android Heroes Biography", "The first line of code" and so on, but also read a lot of great God's blog, but even so, when I see so much code, has not really started to knock the code, So I always feel that the custom view is a very inscrutable technology, we these small white is difficult to touch, but when last night after watching a chicken soup, feel that people still have to learn to focus on, to withstand loneliness, to sink the gas. So in the next few days, I will continue to update their blog, hoping to get everyone's supervision, but also hope to grow together.
In general, you don't have to customize your own controls until you're forced to. After all, the Android API has already provided me with such a powerful control, and you can also find that even such a powerful Google, many controls still have their own bugs, not to mention the controls we write ourselves, of course, By customizing the controls to deepen our understanding of the Android controls, this is also a good way to step forward. All right, let me get to the bottom of this.
Bezier curve This topic, a lot of great God's articles are involved, in Guo Shen's micro-letter public number inside a special article about: http://mp.weixin.qq.com/s?__biz=MzA5MzI3NjE2MA==&mid= 2650236243&idx=1&sn=00f003c809b1e3a3e5e7cb372d3ec970&scene=0#wechat_redirect, so I'm not going to talk about this here. The coding phase starts below.
Create a new class file named Mylineview, let it inherit view, implement its three constructors, and then initialize some of the data such as brushes, Path, circles, and so on. The code is as follows:
1. Define Variables
Paint Mpaint, MPaint2;
Path MPath = path ();
Mviewwidth, Mviewheight;
Mwidth, Mheight;
R, Rarc, X;
Percent = f;
RECTF RECTF;
PointF mpointf = PointF (,);
Initializing data within a constructor
Public Mylineview (context, AttributeSet attrs) {
Super (context, attrs)
mpaint = new Paint ()
Mpaint (color)
mpaint ()
mpaint (Paint)
mpaint () mPaint2
= new Paint () MPaint2
(color)
MPaint2 ()
mPaint2 (Paint)
}
The preparations have been made, followed by a onsizechanged () method of the Copy view, the name incredible, which is called when the size of the control has changed. We're assigning variables here, the code is as follows:
(W, H, oldw, oldh) {
. onsizechanged (W, H, OLDW, OLDH);
Mviewwidth = W;
Mviewheight = h;
Mwidth = Mviewwidth-getpaddingleft ()-getpaddingright ();
Mheight = Mviewheight-getpaddingtop ()-Getpaddingbottom ();
R = Math.min (Mwidth, mheight) * f;
RECTF = RECTF (R, R, R, R );
}