Android Basics Getting Started tutorial--8.3.14 paint Several enumeration/constant values as well as shadowlayer shadow effects
tags (space delimited): Android Basics Getting Started Tutorial
Introduction to this section:
Getting Started with Android Basics tutorial--8.3.1 Three drawing Tools class detailed paint method parameters there we were exposed
A few things: Paint.style,paint.cap,paint.join and so on, these are some of the enumeration values in Paint, related
Methods we can set these enumeration values for specific effects such as: Style: Brush style, join graphics, etc.
In this section we go into the source of the paint, we will introduce these enumeration values, and we also stop to say this Shadowlayer
Set a paint! with a shadow effect To open the source of the paint class, we can see the following enumeration values:
OK, no BB, start this section!
1.get Enumeration Usage:
I do not know everyone is unfamiliar with the enumeration, and here put the Paint.style related call code (enumeration with the parameter constructor method)
, let us realize:
Public enumStyle {//Define enumerations, assign values by parenthesesFILL (0), STROKE (1), Fill_and_stroke (2);//Parametric construction methodStyle (intNativeint) { This. nativeint = Nativeint; }Final intNativeint; }//How to set the brush style Public void SetStyle(Style style) {Native_setstyle (mnativepaint, style.nativeint); }//jni the way to set the brush style, here we don't need to pay attention Private Static native void Native_setstyle(LongNative_object,intStyle);
Let's explain how these enumeration values work!
1.paint.style
Effect: The style of the brush
Optional values:
- Fill: Fills the interior (default)
- Stroke: stroke only
- Fill_and_stroke: Fills the interior with the stroke
Method invocation:SetStyle (Paint.style Style)
Corresponding effect:
2.paint.cap
Function: Stroke style, set the drawing at the beginning of the brush (the brush begins with the 1th and last one o'clock)
Optional values:
- Butt: stroke is rectangular and does not exceed path (default)
- ROUND: Stroke is round
- Square: strokes are squares
Method invocation:setstrokecap (paint.cap Cap)
Corresponding effect: Usually we draw the first directly, the other two will be more than the normal area of the outer, the second
It's rounded, and the third one is a rectangle!
3.paint.join
Function: Set the state of the junction, for example, your line is made up of multiple small lines, the shape of the stitching place
Optional values:
- MITER: A sharp corner at the Junction (default)
- ROUND: Arc at junction
- Bevel: Straight line at the junction
Method invocation:setstrokejoin (paint.join Join)
General arc used much, can see before the Erase Beauty clothes demo display
There is also a setstrokemiter (float miter) that sets the tilt of the stroke, miter > = 0;
such as: The pencil when used as a child, when cutting oblique and vertical cut out of the nib effect is not the same.
This is primarily used to set the style at which strokes are joined. Comparisons can be compared with setstrokejoin ().
4.paint.align
Function: Sets the way in which the text is drawn, that is, the [x, y] starting coordinates relative to the drawing text
Optional values:
- Left: Draws text to the ieft of the start coordinate
- Right: Draws text to the left of the start coordinate
- Center: Draw text centered in fact coordinates
Method invocation:settextalign (paint.align Align)
Corresponding effect: also call Settextsize () to set the size of the drawing text ~
5.paint.fontmetrics and Paint.fontmetricsint
Font properties and measurements, the other two methods are the same, but the latter takes the value is a shape,
Here we choose Fontmetricsint to explain to you, there are the following five constant values, the reference point here is:
The position of the underline (Baseline)
- top: Distance from the highest character to baseline, which is the maximum value of ascent
- Ascent: The distance from the highest character to the value of baseline
- descent: The distance from the underline to the lowest character
- Bottom: The distance from the underscore to the lowest character, which is the maximum value of descent
- Leading: The distance between the descent of the previous line of characters and the ascent of the next line
Let's look at a few diagrams to help understand the following:
Then we randomly draw a bunch of letters to print out these values:
canvas.drawtext ("abcdefghijklnmopqrstuvwxyz", N., mPaint1);
log.e ("HEHE", Mpaint1.getfontmetricsint (). toString ());
Running, we can see that the printed log is as follows:
It should not be difficult to understand how to think and draw a picture after reading. Here we know under the good if you want to be more
In-depth study, you can refer to this article: Android string advanced Three: Font properties and Measurement (FontMetrics)
6.ShadowLayer Setting the Shadow effect
We've taught you to set a shadow effect for textview text in the TextView section, and paint actually provides settings
Shadow Effects API:Setshadowlayer (float radius, float dx, float dy, int shadowcolor)
Parameters: Radius is the angle of the shadow, DX and dy are the distance of the shadow on the X and Y axes, and the shadowcolor is the color of the shadow
We can write a very simple sentence to verify under:
mPaint1.setShadowLayer(5,0,0,Color.BLACK);canvas.drawText("毕竟基神~"400400, mPaint1); //绘制文字
The effect is as follows :
In addition we can call Clearshadowlayer () to clear this shadow layer ~
This section summarizes:
OK, this section explains a few of the enumeration values and static constants in the paint, as well as the shadowlayer as a brush
Set the shadow effect or call Clearshadowlayer () to clear the shadow layer ~ Actually, these things can be seen on their own source and
Document, have doubts to write a demo, a lot of things on the natural clear, well, say so much, thank you ~
In addition, you may not know where to see my QQ, but you can try to add a group of good, usually also to work,
A two good, a bunch of people, powerless, sometimes help solve problems, the results of a day do nothing, hope you understand,
If you have questions Add Piggy Group, group management is very enthusiastic:421858269~
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Basics Getting Started tutorial--8.3.14 paint several enumerations-constant values and Shadowlayer shadow effects