在我的代码中我有一个Image View
在我的 XML 布局中,我不断在代码中更改源图像。现在我想知道每次生成的图像的宽度和高度。
我尝试使用getWidth()
, getHeight(),
getMeasuredWidth(),
and getMeasuredHeight()
,但它们都返回 0。
我怎样才能得到这个?
你打电话去哪里getWidth()
and getHeight()
在图像视图上?如果您从以下地方致电onCreate()
在活动中,它不会起作用。您需要等待活动窗口附加,然后调用getWidth() and getHeight()
在图像视图上。您可以尝试拨打电话getWidth() and getHeight()
from onWindowFocusChanged()
您的活动方法。
@Override
public void onWindowFocusChanged(boolean hasFocus){
int width=imageView.getWidth();
int height=imageView.getHeight();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)