首先,看getWidth()的官方说明: public final int getWidth () Added in API level 1 Return the width of the your view. Returns The width of your view, in pixels. 返回view的宽度,说的不详细,再看getWidth源码: <
getWidth 以ImageView为例,源代码: public final int getWidth() {return mRight - mLeft;} 可以发现该方法是final的,只有在View类中有。而在View类中mRight与mLeft的赋值只有在protected boolean setFrame(int left, int top, int r