Android獲取控件的高度(height)

想要獲取Android控件的高度和寬度,方法有點繞,介紹以下:html

在onCreate或其餘方法中直接獲取屬性是無效的。java

重載activity的onWindowFocusChanged方法,可在其中獲取控件的寬和高,代碼以下:ide

@Override
public void onWindowFocusChanged(boolean hasFocus) {
   super.onWindowFocusChanged(hasFocus);

   int height = layoutData.getMeasuredHeight();
       
   //...

}
相關文章
相關標籤/搜索