它是我的代码。referButtun 是 imageButton
@Override
protected void onResume() {
super.onResume();
referButtun.getHeight();
Log.d("Base",""+referButtun.getHeight());
}
它是我的代码。referButtun 是 imageButton
@Override
protected void onResume() {
super.onResume();
referButtun.getHeight();
Log.d("Base",""+referButtun.getHeight());
}
这就是你应该这样做的方式:
final ViewTreeObserver vto = referButtun.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Log.d("Base",""+referButtun.getHeight());
// don't forget to remove the listener, we don't need it just this one time
vto.removeGlobalOnLayoutListener(this);
}
});
作为替代方案,您可以使用
referButtun.post(new Runnable() {
@Override
public void run() {
Log.d("Base",""+referButtun.getHeight());
}
});