Basic functions you need to know about Android custom view
I want to say something before I start .. Iphone alarm, in 12-hour format. I successfully set the alarm clock to PM, leading to a missed flight. Distressed to change the signature fee.
There is nothing to do with the waiting machine ing. Let's write the basic functions that must be mastered to learn the custom view. Here are some common examples.
First, a painting is required for draw on the Canvas. Which of the following are commonly used paint brush functions. Since the wood has a debugging environment, the function is basically written silently. If there are any mistakes, please comment on them!
Paint p = new Paint (); // set the Paint color p. setColor (Color. parseColor ("#2EA4F2"); // set the paint brush style: FILL all FILL to draw only the outline STROKEp. setStyle (Paint. style. STROKE); // set the width of the paint brush p. setStrokeWidth (8); // you can specify whether the value is anti-sawtooth. setAntiAlias (true );
// Set the text size p. setTextSize (30); // measure the string length p. MeasureText ("Hello World ");When we have a paint brush, we can draw basic images.
Line:
// Draw a line canvas. drawLine (100,100, 100,100, p) from 0 );
Triangle & Polygon
Is implemented using the Path class. The Path class provides the dot-drawn line function. For more information, see the example.
Path. moveTo (); // specifies the starting point path of the path. lineTo (10, 10); // draw a path to 10, 10. lineTo (5, 3); // continue to draw a path from 10, 10 to 5, 3. close; // draw a line to form a closed space canvas. drawPath (path, p );
Rectangle:
// Draw a rectangle. The coordinates in the upper left corner are 100 in the lower right corner of, and 50 canvas. drawRect (, 50, p );
Rounded rectangle:
// A rectangle RectF rectF = new RectF (, 50); // draw a rectangle with rounded corners. The size is rectF. the radius of the Left rounded corner and the radius of the right rounded corner are canvas in. drawRoundRect (RectF, 20, 20, p );
Circle
// Draw a circle with a center of 50 and a radius of 100 canvas. drawCircle (, p );
Arc shapeNote that the second parameter here is calculated from three o'clock to 0 °, so if you want to draw from the middle of 12, it is 270 °. The fourth parameter is to determine whether it passes through the center of the circle (you can change this parameter to know the difference ).
// Draw an arc. The rectangle where the arc is located is rectF starting from 270 °. Draw 90 ° without passing through the center canvas. drawArc (rectF, 90, false, p );
The above are basically the most basic functions used by custom views.