Custom Control,

Source: Internet
Author: User

Custom Control,

From the beginning of the series, we have proposed rect, canvas, painting and other pitfalls. Here we will first explain, such as rectangles, canvases, and brushes.

Basic usage of paint
// 1. create a Paint brush private Paint mPaint = new Paint (); // 2. initialize the brush private void initPaint () {mPaint. setColor (Color. BLACK); // set the paint brush color mPaint. setStyle (Paint. style. FILL); // set the paint brush mode to FILL the mPaint. setStrokeWidth (10f); // set the paint width to 10px} // 3. initialize In the constructor (XXXView is the custom View name) public XXXView (Context context, AttributeSet attrs) {super (context, attrs); initPaint ();}

For more information, see the paint brush modes.

Paint Brush Mode

STROKE // STROKE

FILL // FILL

FILL_AND_STROKE // fill the stroke

You can use Shader for painting.

But instead of using the Shader class, it uses several subclasses. Specifically, there are several LinearGradient RadialGradient SweepGradient BitmapShader ComposeShader.

LinearGradient linear gradient

LinearGradient (float x0, float y0, float x1, float y1, int color0, int color1, Shader. TileMode tile)

Parameter introduction:

X0 y0 x1 y1: position of the two endpoints of the gradient

Color0 color1 is the color of the endpoint tile: The color rule outside the endpoint range. The type is TileMode. TileMode has three optional values: CLAMP, MIRROR, and REPEAT. The CLAMP will continue the color of the endpoint outside the endpoint; MIRROR is the image mode; REPEAT is the REPEAT mode

RadialGradient radiation gradient

RadialGradient (float centerX, float centerY, float radius, int centerColor, int edgeColor, TileMode tileMode)

Parameter introduction:

CenterX centerY: coordinates of the Radiation Center

Radius: radiation radius

CenterColor: The color of the Radiation Center.

EdgeColor: The color of the radiant edge.

TileMode: color mode outside the radiation range.

SweepGradient scan gradient

SweepGradient (float cx, float cy, int color0, int color1)

Parameter introduction:

Cx cy: scanning center

Color0: the starting color of the scan.

Color1: End color of Scan

BitmapShader (uses Bitmap pixels to fill the image or text)

BitmapShader (Bitmap bitmap, Shader. TileMode tileX, Shader. TileMode tileY)

Parameter introduction:

Bitmap: used for template?

Bitmap object

TileX: horizontal TileMode

TileY: vertical TileMode.

ComposeShader hybrid coloring er

ComposeShader (Shader shaderA, Shader shaderB, PorterDuff. Mode mode)

Parameter introduction:

ShaderA and shaderB: Used in succession

Shadermode: the superposition mode of two Shader, that is, how to draw shaderA and shaderB together. It is of the PorterDuff. Mode type, so it is necessary to put a classic image. Haha

SetStrokeCap of the paint brush

Paint. setStrokeCap (cap) can be used to set the vertex shape, but this method is not specifically used to set the vertex shape, but a method to set the line endpoint shape. The endpoint has three similar draw lines: ROUND, BUTT, and SQUARE)

Paint. setStrokeJoin (Paint. Join join) can be used to set the corner shape. Three values can be selected: MITER tip, BEVEL width, and ROUND rounded corner. The default value is MITER.

Paint. setStrokeMiter (float miter) is a supplement to setStrokeJoin (). It is used to set the maximum extension length of the MITER corner.

Haha, I am very embarrassed to introduce some methods of the paint brush. Although simple painting only requires the basic method, I will be able to use it in the future. I will go into details here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.