---
title: "关于View.getHeight()函数调用时机"
author: "vocaloid"
date: "2013-05-25T12:21:11Z"
tags: []
categories: ["移动开发"]
slug: "view-getheight"
draft: false
lastmod: "2013-05-25T12:21:11Z"
id: 1875992
url: "https://vocaloid.iteye.com/blog/1875992"
---

转自：[http://appcnet.diandian.com/post/2012-05-10/19071820](http://appcnet.diandian.com/post/2012-05-10/19071820)

项目过程中遇到一个问题，就是  
获取  
一个View的高度却返回0的问题，在onCreate()中不行，因为View还没有创建。在onResume()中获取却也是0，(百度后说在这用一定的延时后获取是能成功的)。最后的解决方法是，通过 onWindowFocusChanged() 实现。

如：

public void onWindowFocusChanged(boolean hasFocus) {  
 ...

alpha.setHight(alpha.getHeight());  
...

}

此时能正常获取Activity中View的高度了！！