After reading the SDK today, I am not very familiar with this things. Google may gain some benefits after a while. The following is my understanding.
Getwidth indicates the actual size of a view.
Getmeasuredwidth indicates the size of a view in the parent view.
What is the usage?
- Getwidth is 0 in oncreat .. it is strange that I found the cause: When a view object is created, Android does not know its size, so the getwidth () and getheight () returns 0, the actual size is calculated only when the layout is calculated. Therefore, it is interesting to find that ondraw () can achieve the length and width. So how can we get it at oncreat?
Width = activity. getwindowmanager (). getdefadisplay display (). getwidth ();
Height = activity. getwindowmanager (). getdefadisplay display (). getheight ();
2. getmeasuredwidth must be obtained after the parent view or the measure () function is called by itself. The measure function is used to calculate the space required by the function.