Android -- getWidth () and getMeasuredWidth ()
Return the width of the your view. returns The width of your view, in pixels. source code: public final int getWidth () {return mRight-mLeft;} getwidth returns the right coordinate to reduce the coordinate minus the left coordinate, which can be determined after the layout, that is to say, getwidth can be called only after layout. Therefore, the width obtained by getWidth () is the width of the entire View after the layout is set. GetMeasuredWidth () Return the full width measurement information for this view as computed by the most recent call to measure (int, int ). this result is a bit mask as defined byMEASURED_SIZE_MASK and MEASURED_STATE_TOO_SMALL. this shoshould be used during measurement and layout calculations only. use getWidth () to see how wide a view is after layout. returns The measured width of this view as a bit ma Sk. The last time the measure () method was called to measure the View width, It should be used only for measurement and Layout calculation. Let's look at The source code: public final int getMeasuredWidth () {return mMeasuredWidth & MEASURED_SIZE_MASK;} return The raw measured width of this view to obtain The original measurement width. Therefore, getMeasuredWidth () is the width occupied by the View content after the View content is measured. The premise is that you must call measure () in the onLayout () method of the parent layout or the onDraw () method of this View; (you can define the value of the parameter in measure ), otherwise, you will get the same result as getWidth. Difference getMeasuredWidth: The width occupied by the View content after the content on the View is measured. GetWidth: the width of the View after the layout of the number is set. GetMeasuredWidth: When the custom view overwrites onLayout, we want to get the original width of the view after dynamically loading the view with layoutinflater. GetWidth: it is usually displayed after the view has been laid out. To get the width.