Custom controls:

1. Composite controls: This custom control does not require us to draw, but uses native controls to combine into new controls, such as title bar style.

2. Inherit the original control: this custom control in the native control to provide methods, you can add some methods. For example, make rounded corners and round pictures.

3. Fully custom controls: All the content displayed in this View is drawn by ourselves. Like making a water ripple progress bar.

OnMeasure()—->OnLayout()—->OnDraw()

Step 1: OnMeasure(): measure the attempt size, recursively call the measure method from the top-level parent View to the child View, and the measure method calls back to the OnMeasure.

Step 2: OnLayout(): determine the position of the View, carry out the page layout, recursively call the view. layout method from the top parent View to the child View process, that is, the parent View according to the layout size and layout parameters obtained by measure child View in the previous step, put the child View on the appropriate position.

Step 3: OnDraw() : Draw an attempt, ViewRoot creates a Canvas object and calls OnDraw(),

Six steps: 1. Draw the background of the attempt; 2. Save the Layer of the canvas. 3. 5. Restore the Layer; 6. Draw a scroll barCopy the code

I’m just going to record the View, the ViewGroup event distribution

1. There are only two main actors in Touch event distribution: ViewGroup and View. A ViewGroup contains onInterceptTouchEvent, dispatchTouchEvent, and onTouchEvent.

View contains dispatchTouchEvent and onTouchEvent. The ViewGroup inherits from View.

2. The ViewGroup and View form a tree structure, and the root node is a ViewGroup contained within the Activity.

3. Touch events are also composed of Action_Down, Action_Move and Action_UP. In a complete touch event, there is only one Down and one UP, and several Move events can be 0.

4. When the Activity receives a Touch event, the traversal of the child view is distributed as a Down event. The traversal of the ViewGroup can be considered recursive. The purpose of the distribution is to find the view that actually handles the full touch event, which will return true on the onTouchEvent result.

5. When a child view returns true, the distribution of Down events will be aborted, and the child view will be recorded in the ViewGroup. The subsequent move and UP events will be directly processed by the child view. Because the child view is saved in the viewGroup, when the node structure of the multi-layer viewGroup, the upper viewGroup will save the viewGroup object of the view that actually processes the event. ViewGroup0->ViewGroup1->TextView, TextView returns true, it will be saved in ViewGroup1, and ViewGroup1 will return true, it will be saved in ViewGroup0, When Move and UP events come, they are passed from VIewGroup0 to ViewGroup1. And then it passes from ViewGroup1 to TextView

6. If no child View in a ViewGroup captures a Down event, the ViewGroup’s own onTouch event is emitted. This is triggered by calling the super.DispatchTouchEvent function, the dispatchTouchEvent method of the parent View class. Fires the Activity’s onTouchEvent method when none of the child Views handle it.

OnInterceptTouchEvent has two functions: 1. Intercept the distribution of Down events. 2. Abort the transmission of UP and Move events to the target View so that the ViewGroup of the target View can capture UP and Move events