About interview questions
For example, if looking for a job is understood as a college entrance examination, the interview is the college entrance examination, and the "real questions" on the market are mock test papers. We will easily tend to look for the "real questions" of the corresponding company before the interview, focus on preparation, and look forward to the success of the "betting". But in fact, even if you interview the same company, it will have different departments, different business lines, and different interviewers. Even if you meet the same interviewer, he may not always inspect exactly the same content every time. Think about those good students in the college entrance examination. They certainly don't rely on "being a question" to get good results. Most of them rely on their usual accumulation and flexible grasp of knowledge points. The same is true for interviews. Persevering in searching questions, taking the interview questions as the focus for "review", it is better to draw out the "exam syllabus" yourself, check the mastery of each knowledge point one by one, and review more comprehensively.
My view on interview questions has always been relatively conservative. This type of article is generally just content handling, it will have some deviations and misunderstandings, and the most important thing is that a few questions are thrown there, and nothing is produced. . This is why I added some interview skills in my last interview summary. When I sorted out the interview questions, I didn't mention which company they came from. I just don't want everyone to treat them differently.
Saying this is not to say that the interview questions are useless, but I hope that everyone will not be superstitious about the interview questions and pay more attention to those technical articles with quality and depth. Interviews assess knowledge points rather than specific questions. The role of interview questions is to measure our knowledge and make it easier for us to check and fill vacancies. The more we talk about it, the more it looks like an "exam".
1. View rendering mechanism is divided into:
- onLaout and onMeasure
- onDraw mapping mechanism
2. Common views include:
1.RecycleView
- Interpret the source code
- LayoutManager LayoutManager
- Item Decoration ItemDecoration
- ViewHolder and recycling reuse mechanism
2.CardView
- Source code solution
- The realization principle of rounded shadow
- Adaptation of shadows and margins below 5.0
3.viewpager
- Loading mechanism and how to optimize
- How to combine with Fragment
4.Webview
- Principle analysis
- JS and java interaction
- Multi-threaded WebView use
- WebView and native communication framework
Three. Layout ViewGroup
- ConstaintLayout
- LinearLayout
- RelativeLayout
- FrameLayout
- GridLayout
Four. View drawing process
4.1 Custom controls:
1. Combination controls . This kind of custom control does not need to be drawn by ourselves, but a new control composed of native controls. Such as the title bar.
2. Inherit the original controls . In addition to the methods provided by the native control, this custom control can add some methods yourself. Such as making rounded corners, round pictures.
3. Completely customizable controls : All the content displayed on this View is drawn by ourselves. For example, make a water ripple progress bar.
View drawing process:OnMeasure()——>OnLayout()——>OnDraw()
- Step 1
OnMeasure()
: Measure the size of the view. The measure method is called recursively from the top-level parent View to the child View, and the measure method calls back OnMeasure. - Step 2:
OnLayout()
Determine the View position and perform page layout. The process of recursively calling the view.layout method from the top-level parent View to the child View, that is, the parent View places the child View in a suitable position according to the layout size and layout parameters obtained by the child View in the previous step. - The third step
OnDraw()
: Draw the view.
ViewRoot creates a Canvas object and then calls OnDraw().
Six steps:
- Draw the background of the view;
- Save the layer of the canvas (Layer);
- Draw the content of View;
- Draw View subviews, if not, don’t use them;
- Restore layer (Layer);
- Draw a scroll bar.
4.2View, ViewGroup event distribution
1. There are only two protagonists in Touch event distribution: ViewGroup and View.
ViewGroup
include onInterceptTouchEvent
, dispatchTouchEvent
, onTouchEvent
three related events.
View
contains dispatchTouchEvent
, onTouchEvent
two related events.
Among them, ViewGroup inherits from View.
2. ViewGroup and View form a tree structure, and the root node is a ViewGroup contained within the Activity.
3. Touch events are Action_Down、Action_Move、Aciton_UP
composed of, in a complete touch event, there is only one Down and Up, and there are several Moves, which can be 0.
4. When Acitivty
the Touch event is received, it will traverse the child View to distribute the Down event. ViewGroup
The traversal of can be regarded as recursive. The purpose of distribution is to find the View that really needs to handle this complete touch event, and this View will onTouchuEvent
return true in the result.
5. When a child View returns true, the distribution of the Down event will be suspended, and ViewGroup
the child View will be recorded in the same time . The subsequent Move and Up events will be directly processed by the child View. Since the child View is stored in ViewGroup
the multi-layer ViewGroup
node structure, the upper level will ViewGroup
save the ViewGroup
object where the View that actually handles the event is located : if it returns true ViewGroup0-ViewGroup1-TextView
in the structure TextView
, it will be stored in the ViewGroup1
middle and ViewGroup1
will also return true, is saved in ViewGroup0
. When the Move and UP events come, they will be ViewGroup0
passed from to ViewGroup1
and then from ViewGroup1
to TextView
.
6. When ViewGroup
the time does not capture all child View Down event will trigger ViewGroup
its own onTouch
event. The way to trigger is to call a super.dispatchTouchEvent
function, that is, the dispatchTouchEvent
method of the parent class View . Trigger the Acitivity的onTouchEvent
method when all child views are not processed .
7. onInterceptTouchEvent
There are two functions:
- Intercept the distribution of Down events.
- The transmission of Up and Move events to the target View is suspended, so that the ViewGroup where the target View is located captures the Up and Move events.
At last
At the end of the article, I will put a small benefit for everyone, click on my GitHub to receive
There are many technical experts in the group. If you have any questions, you are welcome to communicate with all netizens. The group still shares high-level Android learning video materials and interview materials for free from time to time~
Secretly say: The masters in the group are like clouds, welcome everyone to join the group and discuss with the big guys!
Share high-level Android learning video materials and interview materials for free~**
Secretly say: The masters in the group are like clouds, welcome everyone to join the group and discuss with the big guys!
[External link image is being transferred...(img-bCY5I1x7-1611297609278)]