The size of a view is expressed with a width and a height. A view actually possess two pairs of width and height values.
The first pair is known as measured width and measured height. These dimensions define how big a view wants to be within its parent. The measured dimensions can be obtained by calling getMeasuredWidth()
andgetMeasuredHeight()
.
The second pair is simply known as width and height, or sometimes drawing width and drawing height. These dimensions define the actual size of the view on screen, at drawing time and after layout. These values may, but do not have to, be different from the measured width and height. The width and height can be obtained by calling getWidth()
and getHeight()
.
大概意思就是getWidth和getHeight获取的是View当前实际显示的大小,而getMeasured相关的函数则获取的是View在父类中计算的需要占用的大小。
联系客服