I. Common methods of Canvas

  • DrawLine: drawLine, drawPath: drawColor: I’m just going to fill the View display area with a certain color with drawRect drawRoundRect drawBitmap drawText drawCircle drawPoint and so on all of these methods are the same as drawlines Also according to the method name can be seen to draw the content, according to the need to pass in parameters
  • Rotate save the current state. Restore: The two methods are generally used in combination, with save before and restore after, to ensure that operations between the two functions will not affect the graph originally drawn on the canvas. Some rotation and other operations will be performed in the middle, and the previous state can be used after restore. So that the operations in between do not affect the possible operations

2. Paint brushes

SetTextSize () : If you want to draw text, you will need to set the font size. Otherwise, you will need to set the width of two lowercase ‘x’ letters by default. Pass in a hexadecimal color parameter, which can be set to ARGB color setStyle(int style): SetStrokeWidth (float width) setStrokeWidth(float width) setTextSkewX: Setextalign: SetLetterSpacing: Sets character spacing setStrikeThruText: sets text strikeout setUnderlineText: Sets text underline setAlpha: setLetterSpacing: sets character spacing setStrikeThruText: Sets text strikeout SetAntAlias (Boolean): Anti-aliasing setDither(Boolean): Anti-jitter. This determines how to down-sample when drawing an image if there is more than the maximum effect the screen can display. If it is false, the drawing speed will be faster, but the color accuracy will decrease (for example, 8888->565). True will try to correct these errors in the down-sample, making the picture softer. setFlags(int flag): For example, setFlags(ANTI_ALIAS_FLAG) is equivalent to setAntiAlias(true). Paint provides the reset() method. BreakText: computes a string of specified length. Reset: resets the brush

3. Invalidate method

The layout() procedure will not be called if the size of the View has not changed, and only those views that need to be redrawn will be drawn. When invalidate() is requested, the view is drawn. 1. Call the invalidate() method directly and request to re-draw (), but only draw the caller itself. 2. SetSelection () method: redraw (), but only the caller is drawn. 3. SetVisibility () method: When the View is VISIBLE in INVISIBLE transformation, the invalidate() method will be called indirectly, and the View will be drawn. 4. SetEnabled () method: request redraw (), but does not redraw any view including the caller itself.

The requestLayout method

This causes the measure() procedure and layout() procedure to be called. Description: The layout rearrangement of the View tree includes both measure() and layout() procedures. Draw is not always executed, but only when the View position is changed. To redraw the view, you need to call the requestLayout() function, which will cause the requestLayout() operation. RequestLayout () and invalidate methods are called indirectly when the View’s VISIBLE state changes from INVISIBLE/ VISIBLE to GONE. At the same time, since the entire View tree size changes, the measure() and draw() processes are called, and again, only views that need to be “redrawn” are drawn.

RequestFocus function description

Description: Request the draw() process of the View tree, but only draw views that “need redrawing.” Speaking of passing limits, the MeasureSpec class is a MeasureSpec class that is used throughout the measure process to pass the parent’s constraints on the child View’s size measurements. In simple terms, this class holds two types of data. 1, the child View is currently located in the parent layout of the specific size. 2, the parent layout of the child View restrictions type. The restricted types are UNSPECIFIED. 1. UNSPECIFIED. It means that I can give you as much as the sub-view wants. You can feel free to use the measure without worrying about anything else. Never mind the size values I passed you. (Actually, higher versions of Android recommend that the size be set to 0 as long as this mode is used.) MeasureSpec = MeasureSpec = MeasureSpec = MeasureSpec = MeasureSpec = MeasureSpec = MeasureSpec = MeasureSpec = MeasureSpec = MeasureSpec 3. AT_MOST It means that according to my current situation, considering the size parameters specified by you, you can just measure a size that can exactly cover your content under the premise of not exceeding the size I set for you.