我们很多次测量控件高度和宽度都是0
这里有个方法和大家分享出来
直接上代码:
View view = View.inflate(getApplicationContext(),R.layout.activity_personal_person_data, null);
int Kw = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
int Kh = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
view.measure(Kw, Kh);
int Kheight =view.getMeasuredHeight();
int Kwidth =view.getMeasuredWidth();
System.out.println("高度-------------"+Kheight);
这样得出的高度和宽度就不是0啦