在onCreate中无法通过getHeight方法获取View的宽高。我们可以通过MeasureSpec实现。
int w = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
textView.measure(w, h);
int width =textView.getMeasuredWidth();
int height =textView.getMeasuredHeight();
时间: 2024-10-15 18:57:10