视图刚加载的时候获取高宽数值
1.将要获取的View传进去
private void measureView(View view){
ViewGroup.LayoutParams lp = view.getLayoutParams();
if(null == lp){
lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
}
int width = ViewGroup.getChildMeasureSpec(0,0,lp.width);
int height;
int tempHeight = lp.height;
if(tempHeight > 0){
height = MeasureSpec.makeMeasureSpec(tempHeight,MeasureSpec.EXACTLY);
}else{
height = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
}
view.measure(width,height);
}
2.通过下面的方法获取宽高
measureView(mHeaderView);
mHeaderView.getMeasuredWidth();
mHeaderView.getMeasuredHeight();