Android获取控件的高度(height)

想要获取Android控件的高度和宽度,方法有点绕,介绍如下:

在onCreate或其他方法中直接获取属性是无效的。

重载activity的onWindowFocusChanged方法,可在其中获取控件的宽和高,代码如下:

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

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

}

猜你喜欢

转载自blog.csdn.net/zhouyingge1104/article/details/81813688