Daily Archives: 2014 年 01 月 29 日

android view getWidth 和 getHeight 的值为0

The getWidth and getHeight methods will return 0 if the view has not yet been inflated. For example, if you are trying to access it in the onCreate of the Activity, you’ll get zero.

在UI 组件还未显示在界面之前调用getWidth和getHeight方法通常会得到0。所以不能在onCreate方法里获得组件的width和height.