Detailed explanation and application of Android pathmeasure

Pathmeasure, as its name suggests, is a class used to measure path. It mainly has the following methods:

Construction method

Nonparametric construction method:

Create an empty pathmeasure. Use this constructor to create an empty pathmeasure, but you need to call setpath method to associate with path before using it. The associated path must be created. If the path content is changed after association, you need to re associate it using setpath method.

Parametric construction method

The constructor is to create a PathMeasure and associate a Path. In fact, it is the same as calling setPath after creating an empty PathMeasure. Similarly, the associated Path must also be created. If the Path content is changed after the association, the setPath method needs to be re correlated. This method has two parameters. The first parameter is naturally the associated path. The second parameter is used to ensure that the path is closed. If it is set to true, the path will be closed automatically regardless of whether the previous path is closed or not (if the path can be closed).

Here you need to specify the following forceclosed:

1) No matter what kind of status (true or false) forceclosed is set, the status of the original path will not be affected, that is, after the path is associated with pathmeasure, the previous path will not be changed.

2) The setting status of forceclosed may affect the measurement results. If the path is not closed, but forceclosed is set to true when associated with pathmeasure, the measurement results may be slightly longer than the actual length of the path, and the status when the path is closed is obtained.

setPath

Setpath (path path, Boolean forceclosed) method is to associate a path, which needs to be created in advance.

isClosed

The isclosed method is used to determine whether the path is closed, but if you set forceclosed to true when associating the path, the return value of this method must be true.

getLength

The getlength () method is used to get the length of the path.

nextContour

We know that path can be composed of multiple curves, but whether it is getlength, getgetsegment or other methods, it will only run on the first line segment, and this nextcontour is used to jump to the next curve to the method. If the jump is successful, it will return true. If the jump fails, it will return false. Note: the effect of using multipath needs to turn off hardware acceleration.

getSegment

Boolean getsegment (float startd, float stopd, path DST, Boolean startwithmoveto): used to obtain a fragment of path.

Resolution:

1) Return value (Boolean): judge whether the interception is successful. True indicates that the interception is successful, and the results are stored in DST. False indicates that the interception fails, and the contents in DST will not be changed.

2) Startd: the length from the start interception position to the starting point of path. Value range: 0 < = startd < stopd < = total length of path;

3) Stopd: the length from the end interception position to the starting point of path. Value range: 0 < = startd < stopd < = total length of path;

4) DST: the intercepted path will be added to DST. Note: add, not replace;

5) Startwithmoveto: whether moveto is used at the starting point to ensure that the position of the first point of the intercepted path remains unchanged.

be careful:

• if the values of startd and stopd are not within the value range [0, getlength], or startd = = stopd, the return value is false and the DST content will not be changed.

• in Android version 4.4 or earlier, when hardware acceleration is enabled by default, there may be problems in drawing after changing the content of DST. Please turn off hardware acceleration or add a single operation to DST, such as dst.rlinto (0,0)

• the following rules can be used to determine the value of startwithmoveto:

True: ensure that the intercepted path fragment will not deform;

False: ensure the continuity of the path (DST) where the intercepted fragments are stored.

getMatrix

Getmatrix (float distance, matrix matrix, int flags): a matrix that obtains the position of a certain length on the path and the tangent value of the position.

Return value (Boolean): judge whether the acquisition is successful. True indicates success, the data will be stored in the matrix, false fails, and the matrix content will not change;

Distance: the length from the starting point of path, value range: 0 < = distance < = getlength;

Matrix: the encapsulated matrix will store different contents according to the settings of flags;

Flags: specify which content will be stored in the matrix. You can choose:

POSITION_ MATRIX_ Flag (position)

ANGENT_ MATRIX_ Flag (tangent)

getPosTan

Getpostan (float distance, float [] POS, float [] tan): obtain the position coordinates of the specified length and the tangent value of the point.

Return value (Boolean): judge whether the acquisition is successful. True indicates success, the data will be stored in POS and tan, false indicates failure, and POS and Tan will not change;

Distance: the length from the starting point of path, value range: 0 < = distance < = getlength;

Pos: coordinate value of the point, coordinate value: (x = = [0], y = = [1]);

Tan: tangent value of the point, tangent value: (x = = [0], y = = [1]).

The rotation angle of the picture is calculated through the value of the trigonometric function tan. Tan is the abbreviation of tangent, where tan0 is the edge length of the adjacent edge and TAN1 is the edge length of the opposite edge. The atan2 method in math calculates the size of the angle according to the tangent value, and the obtained unit is radian, so the radian is converted to angle.

Draw a magnifying glass, then slowly retreat and disappear along the path of the magnifying glass, and become the loading of circular search. Then, after the loading is completed, draw the magnifying glass along the path. As shown in the effect drawing:

Such a custom view requires the cooperation of knowledge such as pathmeasure and animation.

The above is the detailed explanation and application of pathmeasure. Readers need to do more to understand the essence.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>