view = new View(this) {
@OverrideprotectedvoidonLayout(boolean changed, int l, int t, int r, int b){
super.onLayout(changed, l, t, r, b);
int = view.getWidth();
}
};複製代碼
view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@OverridepublicvoidonLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom){
view.removeOnLayoutChangeListener(this);
int width = view.getWidth();
}
});複製代碼
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 (see Layout for more details.) The measured dimensions can be obtained by calling getMeasuredWidth() and getMeasuredHeight().
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().